繁体   English   中英

与JPanel在另一个JPanel中的JScrollpane

[英]JScrollpane with JPanel in another JPanel

我想在基本JFrame添加另一个JPanel带有JPanelJScrollpane

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);

如果我将带有JPanelJScrollpane直接添加到JFrame ,则JScrollpane工作。 但是现在,当我将帧的大小减小到500像素以下时, JPanel会变小,如第二张图片所示。

之前后

如何使JScrollPane工作?

GridBagLayout正是它所期望的。 当可用空间很小以符合组件的首选大小时,它将使用组件的最小大小。

而是考虑使用BorderLayoutEmptyBorder在滚动窗格周围产生空白区域

您还可以使用GridBagConstraintsweightx/yfillinsets属性

看看如何使用GridBagLayout了解更多详细信息

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM