美好的一天,
我有一个JTabbedPane,每个标签都有自己的类。它的每个ActionListener都有它自己的分离类。 一个ActionPerformed会在设置了一定天数后添加一个带有列的JTable。
这是一个标签:
public class FirstTab {
private JPanel mainPane;
private JPanel weeksPane;
private JButton setWeeksB;
private JLabel matchCheck;
private JPanel modulesPane;
public FirstTab() {
mainPane = new JPanel();
weeksPane = new JPanel();
setWeeksB = new JButton("Voeg weken toe");
matchCheck = new JLabel();
//mainPane.setLayout(new FlowLayout());
mainPane.add(createSchoolDaysPane());
}
public JPanel createSchoolDaysPane() {
JPanel schoolDaysPane = new JPanel();
DefaultTableModel weeksModelTable = new DefaultTableModel();
weeksModelTable.addColumn("Week nummer");
weeksModelTable.addColumn("Dagen");
JTable weeksTable = new JTable(weeksModelTable);
JLabel schoolDaysL = new JLabel("Geef hier het aantal schooldagen (max 200) van het jaar in: ");
JTextField schoolDaysF = new JTextField(10);
SetWeeksPaneAction AWFA = new SetWeeksPaneAction(mainPane, weeksPane, weeksModelTable, weeksTable, matchCheck, setWeeksB);
schoolDaysF.addActionListener(AWFA);
JLabel schoolDaysGivenL = new JLabel();
schoolDaysPane.setLayout(new BoxLayout(schoolDaysPane, BoxLayout.Y_AXIS));
schoolDaysPane.add(schoolDaysL);
schoolDaysPane.add(schoolDaysF);
schoolDaysPane.add(schoolDaysGivenL);
return schoolDaysPane;
}
public JPanel getTab() {
return mainPane;
}
此选项卡包含两个面板,显示的JTable在设置天数后添加到面板中。
正如您注意到列不可见(但它们已设置),因此我被告知要使用ScrollPane。
但是,我无法在JTabbed中传递ScrollPane,因为正常窗格('MainPane' - 容器)通过:
public EindopdrachtJava3() {
frame = new JFrame();
jtp = new JTabbedPane();
firstTab = new FirstTab();
secondTab = new SecondTab();
jtp.addTab("Modules", firstTab.getTab());
jtp.addTab("Samenvatting schooljaar", secondTab.getTab());
frame.getContentPane().add(jtp);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(640, 480);
frame.setLocationByPlatform(true);
frame.setVisible(true);
modules = new HashSet<Module>();
weeks = new HashSet<Week>();
}
public static void main(String[] args) {
new EindopdrachtJava3();
}
此选项卡包含多个面板,并添加到Main类
中的JFrame中JFrame {
JTabbedPane {
Tab 1 {
Panel 1
ScrollPane(JTabel) - But not possible(?)
}
Tab 2 {
....
}
}
我希望尽可能保持模块化,因为这是我目前在GUI中的学习曲线