• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Swing heavy-weight components

 
Guennadiy VANIN
Ranch Hand
Posts: 898
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I could not quite understand:

  • what is the catch if Swing components do not have directly heavy-weight peers but only through its ancestors.


  • If JPanel instance is added as a component to JDialog container then JPanel instance is light-weight and JDialog component is heavy-weight? Corrrect?
    If I am trying to instantiate JPanel component outside of JDialog, then it is already light-weight. Correct?



 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the catch if Swing components do not have directly heavy-weight peers but only through its ancestors.


If you have a Frame with a TextArea, a ComboBox and a Button on it, you will have 4 native peers taking up memory under AWT. If you have a JFrame with a JTextArea, a JComboBox, and a JButton on it, you will have only 1 native peer ( the JFrame ).


If JPanel instance is added as a component to JDialog container then JPanel instance is light-weight and JDialog component is heavy-weight? Corrrect? If I am trying to instantiate JPanel component outside of JDialog, then it is already light-weight. Correct?


You are correct about JPanel being a lightweight component and JDialog being a heavyweight component. But I do not understand how you are going to instantiate JPanel outside of JDialog ( or another top level heavyweight JFrame, JWindow, etc. ). All lightweight components have to have a heavyweight top level component to be drawn on... so you can't just have a JPanel floating around all by itself... it has to be drawn on a JFrame, JDialog, JApplet, or some other top level component.

-Nate
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic