【发布时间】:2018-10-25 17:36:09
【问题描述】:
不知何故,我没有显示滚动窗格。我需要改变什么?
bigP = new JLabel();
setLayout(new BorderLayout());
JPanel helper = new JPanel(new FlowLayout());
helper.add(bigP);
helper.setPreferredSize(new Dimension(500,600));
helper.add(new JScrollPane(bigP, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS));
picPane = new JPanel(new BorderLayout());
picPane.add(helper,BorderLayout.CENTER);
picPane.setMaximumSize(new Dimension(500, 600));
picPane.setVisible(true);
add(picPane, BorderLayout.CENTER);
选择图像后,调用此行:
bigP.setIcon(img);
我发现我肯定需要辅助面板,因为 BorderLayout 只需要一个组件(据我所知)。 不幸的是,尽管图片显示,但我的滚动窗格根本不会显示。
【问题讨论】:
标签: java jpanel jscrollpane imageicon scrollpane