我一直在尝试过去4天,搜索这个网站,试图找到解决如何解决我的JScrollPane问题的答案。我没有查看所有内容,也无法向下滚动。
我尝试过只将组件添加到JScrollPane(工作但不是全部),设置JScrollPane的首选大小(因为我的布局为空而没有工作),以及其他无数的。
这里的代码直接影响我关注的窗口区域:
setResizable(false);
setTitle("Thing Maker");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, WIDTH, HEIGHT);
contentPane = new JPanel();
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
setContentPane(contentPane);
contentPane.setLayout(null);
eastPanel = new JPanel();
eastPanel.setBounds(400, 0, 400, 612);
contentPane.add(eastPanel);
eastPanel.setLayout(null);
buildings = new JPanel();
//buildings.setBounds(2, 2, 400, 612);
buildings.setLayout(null);
buildingPanels[0] = new BuildingPanel(0, 0, 0);
buildings.add(buildingPanels[0]);
for(int i = 1; i < buildingPanels.length; i++) {
buildingPanels[i] = new BuildingPanel(i, buildingPanels[i-1]);
buildings.add(buildingPanels[i]);
}
JScrollPane buildingsScroll = new JScrollPane(buildings, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
buildingsScroll.setBounds(2, 2, 400, 612);
buildingsScroll.getVerticalScrollBar().setSize(10, buildingsScroll.getHeight());
eastPanel.add(buildingsScroll);
BuildingPanel是Swing的JPanel的扩展,非常复杂,我认为它不会直接影响窗口,因为它是一个JScrollPane问题。但是,它与JPanel eastPanel非常相似。
谢谢。