开发者

Removing JPanel from a JFrame in NetBeans

I have several JPanels that contain buttons, labels, etc. that I want to switch between开发者_C百科 from a main JFrame. Currently I am trying to use the this.add(JPanelname); method and this.remove(JPanelname); with the validate(); and repaint(); methods

The problem is it will add the panel to the JFrame but it will not remove it. I am not sure how exactly to go about this.


Maybe you should be using a Card Layout.

Or maybe you should be using modal JDialogs. So whenever you click on the "widjet" a new window is displayed. Then when you close the dialog you are back on your main frame.


If you are constantly switching between JPanels, then a JTabbedPane may be the right thing to use. It should not be necessary to call "validate" or "repaint" when you add or remove a JPanel. Do you have a layout manager installed? Do you make sure to call add/remove only within the UI event thread? Also, typically one does not call "validate()" but rather "invalidate()" to invalidate the container for updates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜