I have a JPanel that contains a bunch of context.
I would like to be able to add the specified JPanel to two JFrames. Any tips?
This is an example of what I would like
public class Test
{
public static void main(String [] args)
{
JPanel panel = new JPanel();
panel.add(new JLabel("Hello world"));
panel.validate();
JFrame frame1, frame2;
frame1 = new JFrame("One");
frame2 = new JFrame("Two");
frame1.add(panel);
frame2.add(panel);
frame1.validate();
frame2.validate();
frame1.setVisible(true);
frame2.setVisible(true);
frame1.pack();
frame2.pack();
}
}
I want both JFrames to display the hello world, not one showing it and the other empty. And if the data is in JPanel updates, I want both JFrames to display it.
Thanks to someone for their help, this has been undermining me for a while.
source
share