我试图让JTable显示在我的论坛上,但我想要一个顶行是一个带有一排按钮的“菜单”。我尝试了多种方法来实现这一点,但我无法让JTable向下移动。我评论过的部分是我一直在玩的东西。
Table1 = new JTable(data, columnNames);
Table1.setPreferredScrollableViewportSize(new Dimension(1000, 600));
Table1.setFillsViewportHeight(true);
JScrollPane scrollPane = new JScrollPane(Table1);
add(scrollPane);
scrollPane.setLocation(0,300);
Container TopMenu = getContentPane();
SpringLayout TopMenuLayout = new SpringLayout();
TopMenuLayout.putConstraint(SpringLayout.WEST, project1, 325, SpringLayout.WEST, TopMenu);
TopMenuLayout.putConstraint(SpringLayout.NORTH, project1, 5, SpringLayout.NORTH, TopMenu);
TopMenuLayout.putConstraint(SpringLayout.WEST, project2, 100, SpringLayout.WEST, project1);
TopMenuLayout.putConstraint(SpringLayout.NORTH, project2, 5, SpringLayout.NORTH, TopMenu);
TopMenuLayout.putConstraint(SpringLayout.WEST, project3, 100, SpringLayout.WEST, project2);
TopMenuLayout.putConstraint(SpringLayout.NORTH, project3, 5, SpringLayout.NORTH, TopMenu);
TopMenuLayout.putConstraint(SpringLayout.WEST, project4, 100, SpringLayout.WEST, project3);
TopMenuLayout.putConstraint(SpringLayout.NORTH, project4, 5, SpringLayout.NORTH, TopMenu);
TopMenuLayout.putConstraint(SpringLayout.WEST, project5, 100, SpringLayout.WEST, project4);
TopMenuLayout.putConstraint(SpringLayout.NORTH, project5, 5, SpringLayout.NORTH, TopMenu);
//TopMenuLayout.putConstraint(SpringLayout.NORTH, Table1, 150, SpringLayout.NORTH, this);
TopMenu.setLayout(TopMenuLayout);
//TopMenu.add(scrollPane);
TopMenu.add(project1);
//TopMenu.add(Table1);
TopMenu.add(project2);
TopMenu.add(project3);
TopMenu.add(project4);
TopMenu.add(project5);