开发者

Java, swing, JFrame and JPanel

开发者 https://www.devze.com 2023-01-30 13:08 出处:网络
I have main window in my program - class that inherit JFrame, this window have JMenuBar. In code I dynamically create instance of JPanel with some components and set this panel to main window as 开发

I have main window in my program - class that inherit JFrame, this window have JMenuBar.

In code I dynamically create instance of JPanel with some components and set this panel to main window as 开发者_运维技巧content pane.

But after this menu bar intersects with my panel, the part of panel is behind menu bar. This continues until I change my window size.

After this intersection disappears, and menu panel placed under menu bar without intersect.

JFrame view = ApplicationContext.getInstance().getView();
JPanel panel = new TherapeuticProfile().getRootPanel();
view.setContentPane(panel);


Doing this after the window is displayed? In which case you will need revalidate.

Doing this off the AWT EDT? In which case you'll need to stop doing that.

(Also statics, as in ApplicationContext.getInstance() are a really bad idea in any program.)

0

精彩评论

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

关注公众号