• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can't refresh the JPanel

 
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This sort of a repost of a similar problem I had previously.

I've got class A (extends JInternalFrame) which has a main method that instantiates a JFrame which holds the JInternalFrame:


And class B (extends JPanel) which is a class variable of class A.

When I instantiate class B I pass it a JTabbedPane from class A (this is the pane that is being used to display class B) and JInternalFrame (this the JInternalFrame which holds the JTabbedPane)

Class B has two JButtons (for a look up, next and previous buttons with the action events handled in class B i.e. class B implements ActionListener)

Now what I need to happen is when the next button is clicked the next screen of results replaces the previous one.

So I've tried to to JTabbedPane.removeAll() (where JTabbedPane is the instance variable passed from Class A to Class B) but nothing is removed. I've also tried to execute .removeAll() on the JPanel holding the JTabbedPane.

I've noticed something a bit odd... If I execute JTabbedPane.removeAll() in the constructor of Class B it works and the look up is blank. But if I execute JTabbedPane.removeAll() during the actionPerformed() nothing happens, I've tried to suibsequently repaint/ revalidate/ validate but it makes no difference.

Another interesting thing is in the constructor I've done the following System.out.println(JTabbedPane.hashCode()); and done the same in actionPerformed() when executed in the different methods they return different hashcodes (meaning they are two different objects???) if they're two different objects then the JTabbedPane in class A and the parameter passed to class B are two different objects (i.e. java has copied from the one giving the second a new memory address???)

I'm quite confused... How should I best tackle the scenario?

Thanks for reading!
 
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Labuschagne:

JFrame frame = new JFrame("IntoBondTest");
frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JInternalFrame internalFrame = new IntoBondSelectionGUI("BONDBOOOK004");

frame.add(internalFrame);



This will work, presuming IntoBondSelectionGUI's constructor calls the equivalent of internalFrame.setPreferredSize() and internalFrame.setVisible(true), but JInternalFrames are intended to be added not to just any Container but to JDesktopPanes.

If, for example, you added two overlapping JInternalFrames like this to a JPanel, then the user would be not be able to bring the lower one on top of the upper one. Their z-order would be fixed.

Better, I think, would be to do something like this:

JFrame frame = new JFrame("IntoBondTest");
JDesktopPane desktop = new JDesktopPane();
frame.setContentPane(desktop); //frame.setLayout(new FlowLayout());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

JInternalFrame internalFrame = new IntoBondSelectionGUI("BONDBOOOK004");
internalFrame.setBounds(40, 40, 300, 200);
internalFrame.setVisible(true);

desktop.add(internalFrame);


I realize that this most likely doesn't answer your question (which I couldn't understand, though it seems to be something about JTabbedPane even though there are no JTabbedPanes in your code) but I felt I should mention it.
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Check this example.

When you remove the JTabbedPane, then you must update the GUI.

jTabbedPane.removeAll();
jTabbedPane.updateUI();

I don�t know if the method updateUI() is part of JTabbedPane, but if it is not, then you could use JPanel. with JPanel you can remove and update your panel.
 
Michael Labuschagne
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies...

I tried using the updateUI scenario and its just not working...

gonna try play around with a few things see if i can find away around the problem... the way java handles objects can be confusing, you expect two objects to be the same object (which they were for some time) and suddenly in another method within the class the vm has decided to copy that object and the two attributes no longer point to the same object.
 
Michael Labuschagne
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies...

I tried using the updateUI scenario and its just not working...

gonna try play around with a few things see if i can find away around the problem... the way java handles objects can be confusing, you expect two objects to be the same object (which they were for some time) and suddenly in another method within the class the vm has decided to copy that object and the two attributes no longer point to the same object.
 
Michael Labuschagne
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies...

I tried using the updateUI scenario and its just not working...

gonna try play around with a few things see if i can find away around the problem... the way java handles objects can be confusing, you expect two objects to be the same object (which they were for some time) and suddenly in another method within the class the vm has decided to copy that object and the two attributes no longer point to the same object.
 
Michael Labuschagne
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for the replies...

I tried using the updateUI scenario and its just not working...

gonna try play around with a few things see if i can find away around the problem... the way java handles objects can be confusing, you expect two objects to be the same object (which they were for some time) and suddenly in another method within the class the vm has decided to copy that object and the two attributes no longer point to the same object.
 
Brian Cole
Author
Posts: 986
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Michael Labuschagne:
I tried using the updateUI scenario and its just not working...



I'm still not sure what problem you're having with JTabbedPane, but I must disagree with Nacho Espinosa. I don't think updateUI() would usually need to be called after tabs are removed.

the way java handles objects can be confusing, you expect two objects to be the same object (which they were for some time) and suddenly in another method within the class the vm has decided to copy that object and the two attributes no longer point to the same object.



The VM does not do that, so you must be mistaken. Can you post a small code sample where you think this is happening so we can clear things up?
 
Michael Labuschagne
Ranch Hand
Posts: 56
Tomcat Server Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My comments about the object being copied were not explained well...

I've completely changed my code and its working now. I don't know what I was doing wrong. I wanted to post a small example to show the problem I'm having but couldn't recreate the problem.

Thanks to everyone who read and tried to help.

Happy Valentine's Day to All!
 
reply
    Bookmark Topic Watch Topic
  • New Topic