When a swing-app is running, some action puts a new item into a frame's contentPane, should validate always be called on the contentPane?? As I understand it, validate() "recomputes" the containers layout, and does what it needs show the user it's new contents. Next: remove(Component c) setVisible(bool flag). Does remove make the component never again, obtainable?? If it doesn't, is remove() the best way to "hide" something(then calling add()), or should it be setVisible(false)??? Maybe I should understand this from the API, but...no... Anyone?? (Being a swing-beginner takes some patience, indeed)
usually in awt times, after u added some components to the frame after it is visible, u needed to make sure to call validate() in order to "validate" (make sure) the components were added (if u didnt u needed to resize the window in order to see the components). however, in swing it is rarly necessary and all components will be shown most of the time with no use of validate(). instead u can use sometimes revalidate() which is the swing version for validate() (but again rarly used in my experience).usually u will use setVisible(true) or false to hide or show containers like dialogs or frames. u can use it also for components. remove() however removes the component from the container. that means the u can add it again later if u wish but for right now u removed it. (the opposite of add).
Thanks! In my appl. I have 5 JPanels(each with a Jtable) Only one should be visible at a time in the JFrame(using BorderLayout). So the best way to switch would be to simply keep adding/removing, or adding all 5 and then using setVisible(). Still I little unclear... (I gave up with CardLayout, never worked)
my suggestion to u is that if u switch the 5 panels a lot, use a cardLayout instead. make another panel and set it to CardLayout. add to it your 5 other panels and then u can switch easily! usually it is not very good design to add and remove components all the time, but if u dont see the NEW panel after adding or removing it then use revalidate(). if u see them then u dont have to.
Could you please give me some sample-code of using CardLayout correctly. I've tried with it for days, but it never worked. I do see that's the way to attack the problem, but HOW!!!??? This is the way I tried: JFrame gets a JPanel cont. cont gets another 5 JPanels holding 5 JTables. Which component should be managed by CardLayout, and how???
In your code JFrame is managed by CardLayout. In my appl. I have several JPanels(in the JFrame), managed by BorderLayout. I mean, in my case CardLayout should NOT be "used" by the JFrame, but of one of it's panels(BorderLayout.EAST in the frame). Should this make a difference? Obvious difference: JFrame-(getContentPane.setLayout(card)) JPanel panel...panel.setLayout(card...). In frames case you add the manager to the frames contentPane, in panels case you "just" add it. Do these two concepts differ???(panel has no container)