[英]JScrollpane with JPanel in another JPanel
我想在基本JFrame
添加另一个JPanel
带有JPanel
的JScrollpane
JPanel outer = new JPanel(new GridBagLayout());
JPanel drawPanel = new JPanel(new GridBagLayout());
drawPanel.add(new DrawingBoard(500,500));
drawPanel.setBackground(Color.WHITE);
JScrollPane scrollPane = new JScrollPane(drawPanel);
outer.add(scrollPane);
this.add(outer, BorderLayout.CENTER);
如果我将带有JPanel
的JScrollpane
直接添加到JFrame
,则JScrollpane
工作。 但是现在,当我将帧的大小减小到500像素以下时, JPanel
会变小,如第二张图片所示。
如何使JScrollPane
工作?
GridBagLayout
正是它所期望的。 当可用空间很小以符合组件的首选大小时,它将使用组件的最小大小。
而是考虑使用BorderLayout
和EmptyBorder
在滚动窗格周围产生空白区域
您还可以使用GridBagConstraints
的weightx/y
, fill
和insets
属性
看看如何使用GridBagLayout了解更多详细信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.