Adding JDesktopPane to JFrame using GridBagLayout

我的梦境 提交于 2019-12-14 03:29:28

问题


How do I add the JDesktopPane to JFrame using GridBagLayout and set its height and width. If I add JDesktopPane that contains JInternalFrame I don't get anything. But works well in case of GridLayout but the problem is I can't set my desired size in it as GridLayout splits equal space among each component added.


回答1:


You will probably need to set the fill and weight attributes of the GridBagConstraints...

GridBagConstraints gbc = new GridBagConstraints();
gbc.weightx = 1;
gbc.weighty = 1;
gbc.fill = GridBagConstraints.BOTH;

This will cause the component to want to push to the limits of the container and will cause the component to fill it's cell within the grid

This override the components preferred size (for the most part)

Take a look at How to Use GridBagLayout for more details...



来源:https://stackoverflow.com/questions/22874242/adding-jdesktoppane-to-jframe-using-gridbaglayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!