hi,

i have an array of JTextPane's.

console 0 uses array[0] jtextpane to see their chat.
console 1 uses array[1] jtextpane etc.

up to them how many jtextpanes they use/consoles they create/open. they can move different chat channels to different consoles or have all channels go to one.

lets say the user has 3 consoles open, what i'd like is for a way to cycle through the chat windows ( jtextpanes) in a single console.

say they hit a button and console one now displays array[1] , hit it again its on 2 hit it again its back on 0.

the other windows would not be effected. i.e. if console 2 was displaying array[1] it would continue to even though console 1 is also now displaying array[1].

can this be done?

Mike

i did some testing. swapping the control so it lived on two windows at once didnt work well but i could make one console, say console[0] the master window, and have a second set of jtextpanes, the second array, that i swap with console 0, syronizeing hte second set like array2, with the document on array; in my example you hit up to cycle through the windows on console 0.


/*import javax.swing.*;

import java.awt.event.*;
import java.awt.*;
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JDialog;
import java.io.*;
import java.net.*;
import java.lang.Thread.*;
import java.applet.*;
import javax.swing.GroupLayout.*;
import javax.swing.colorchooser.*;
import javax.swing.event.*;
import java.lang.Integer;
import javax.swing.text.*;
import java.awt.geom.*;
import java.awt.image.BufferedImage;
import java.applet.*;
import java.awt.event.*;
import java.awt.image.*;
import javax.imageio.ImageIO;
import java.util.concurrent.ConcurrentLinkedQueue;

public class keypress
{


public static void main(String[] args) {
myclass a = new myclass();


}
}// end main class

class myclass {
JTextPane [] panes;
JTextPane [] panes2;

JFrame1 frame;
JFrame1 frame2;
JFrame1 frame3;

myclass()
{

panes= new JTextPane[3];
panes2=new JTextPane[3];
frame = new JFrame1(0);
frame2 = new JFrame1(1);
frame3 = new JFrame1(2);

}
class JFrame1 extends JFrame {

JFrame1()
{

}

JFrame1(int num)
{
setTitle("Tab" + num);
setSize(325,150);
setLocationRelativeTo(null);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

mypanel panel = new mypanel(num);
add(panel);
setVisible(true);
pack();
}
}// end frame
class mypanel extends JPanel
{
JTextField box;
JLabel alabel;
String last;
int mynum;
mypanel(){}

void flip(){
if(mynum==0)
{
remove(panes[mynum]);
mynum=1;
Document doc = panes[1].getDocument();
add(panes2[mynum]);
panes2[mynum].setDocument(doc);
repaint();
}
else if(mynum==1)
{
remove(panes2[mynum]);
mynum=2;
Document doc=panes[2].getDocument();
add(panes2[mynum]);
panes2[mynum].setDocument(doc);

repaint();
}
else if(mynum== 2)
{
remove(panes2[mynum]);
mynum=0;

add(panes[mynum]);
repaint();
}
}// end flip

public void paintComponent(Graphics g)
{
 	Color mycolor, mycolor2, mycolor3;
	mycolor = new Color(5,0,0);
	setBackground(mycolor);
	
	super.paintComponent(g);
}

mypanel(int num)
{

mynum=num;
last="";
alabel = new JLabel("hi there");
box = new JTextField(30);

box.addKeyListener(new KeyListener() {

public void keyPressed(KeyEvent e) {
	int a=e.getKeyCode();
	if(a == 10)
	{	String s=box.getText();
		if(s.length() > 0)
		last=s;
		box.setText("enter pressed");
		} 
}

   public void keyTyped(KeyEvent e) {}
    public void keyReleased(KeyEvent e) {}
});


add(box);
add(alabel);
panes[num]=new JTextPane();
panes[num].setText("this is console" + num);
if(mynum==0)



for(int a=0; a<3; a++)
panes2[a]=new JTextPane();
if(mynum==0)
panes[num].addKeyListener(new KeyListener() {public void keyPressed(KeyEvent e)
 {
	int a=e.getKeyCode();

	if(a == 38)// up
	{
		flip();
	}

    }

   public void keyTyped(KeyEvent e) {}
   public void keyReleased(KeyEvent e) { }

});

if(mynum==0)
{for(int a=0; a<3; a++)
panes2[a].addKeyListener(new KeyListener() {public void keyPressed(KeyEvent e) {
	int a=e.getKeyCode();

	if(a == 38)// up
	{
		flip();
	}

    }

   public void keyTyped(KeyEvent e) {}
   public void keyReleased(KeyEvent e) {}
});
}// end loop


add(panes[num]);
}

}// end panel class
}// end myclass

i think a better solution is not to swap the textpane at all. have an array of styled documents, and whenever i write to a document, say i was writing to console1 , i know write to document 1, and set all consoles using document 1 to that document.

so it makes no diffrence if console1=doc1 and console2=doc2 or say console 1=doc2 and console2=doc2. the data exists in the right document for that data, any console can display it.

Mike

This question has already been answered. Start a new discussion instead.