setting Swing JInternalFrame lnf manually

2019-08-27 19:43发布

UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(207,255,247)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(207,255,247)));
JDesktopPane baTabbedPane = new JDesktopPane();
JInternalFrame iframe = new JInternalFrame("Cheapest To Deliver",true,true,true,true);
iframe.setSize(400,150);
baTabbedPane.add(iframe);

why is my Internal Frame's title background not set on startup?

I've tried setting it on the overall JFrame init but made no difference (By contrast I could change other JFrame ui component look n feel such as MenuItem.background in this location so I thought it might have been because the JInternalFrame was not a top-level component i.e. under a tabbed pane, that maybe it needed changing at some other point, but where?)

Any tips on the correct place to call UIManager.put() for JInternalFrame?

2条回答
Root(大扎)
2楼-- · 2019-08-27 20:07

got it eventually - the call to put() works fine after JInternalFrame creation but I did make it before I added the component to a container. I then still had to set it's UI:

JInternalFrame iframe = new JInternalFrame("blah",true,true,true,true);
UIManager.put("InternalFrame.activeTitleBackground", new ColorUIResource(new Color(248,250,175)));
UIManager.put("InternalFrame.inactiveTitleBackground", new ColorUIResource(new Color(248,250,175)));
javax.swing.plaf.basic.BasicInternalFrameUI ui = 
    new javax.swing.plaf.basic.BasicInternalFrameUI(iframe); 
iframe.setUI(ui); 
查看更多
看我几分像从前
3楼-- · 2019-08-27 20:29

I think you need to make all calls to UIManager.put before you create any Swing components.

查看更多
登录 后发表回答