Table 在 JTabbedPane 中的 scrollPane 中
Table in scrollPane in JTabbedPane
我想使用 JTabbedPane 显示一些 table(每个选项卡中显示一个 table)。
实现起来很容易:您创建一个 JTabbedPane,放置一些 scrollPanes(代表选项卡)然后您只需将 table 添加到您的 scrollPanes。
我的问题是,在 scrollPanes 中你只能添加 table,我还需要添加一个文本框、单选按钮和标签。
我想知道是否还有其他选择。
如果我理解你...你可以将 scrollPane 放到选项卡上并添加到它面板
并在面板中添加您需要的控件和 table;
点赞image
您可以使用 jform 设计器生成代码
jTabbedPane1 = new javax.swing.JTabbedPane();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
jButton2.setText("jButton2");
jPanel1.add(jButton2);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jPanel1.add(jScrollPane2);
jScrollPane1.setViewportView(jPanel1);
jTabbedPane1.addTab("tab1", jScrollPane1);
public static void main(String[] args) {
JFrame Frame = new JFrame();
JTabbedPane jTabbedPane1 = new javax.swing.JTabbedPane();
JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
JPanel jPanel1 = new javax.swing.JPanel();
JButton jButton1 = new javax.swing.JButton();
JButton jButton2 = new javax.swing.JButton();
JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
JTable jTable1 = new javax.swing.JTable();
Frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
jButton1.setText("jButton1");
jPanel1.add(jButton1);
jButton2.setText("jButton2");
jPanel1.add(jButton2);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
},
new String[]{
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jPanel1.add(jScrollPane2);
jScrollPane1.setViewportView(jPanel1);
jTabbedPane1.addTab("tab2", jScrollPane1);
Frame.setContentPane(jTabbedPane1);
Frame.setVisible(true);
}
我想使用 JTabbedPane 显示一些 table(每个选项卡中显示一个 table)。 实现起来很容易:您创建一个 JTabbedPane,放置一些 scrollPanes(代表选项卡)然后您只需将 table 添加到您的 scrollPanes。 我的问题是,在 scrollPanes 中你只能添加 table,我还需要添加一个文本框、单选按钮和标签。
我想知道是否还有其他选择。
如果我理解你...你可以将 scrollPane 放到选项卡上并添加到它面板 并在面板中添加您需要的控件和 table;
点赞image
您可以使用 jform 设计器生成代码
jTabbedPane1 = new javax.swing.JTabbedPane();
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
jButton2 = new javax.swing.JButton();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
jButton2.setText("jButton2");
jPanel1.add(jButton2);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jPanel1.add(jScrollPane2);
jScrollPane1.setViewportView(jPanel1);
jTabbedPane1.addTab("tab1", jScrollPane1);
public static void main(String[] args) {
JFrame Frame = new JFrame();
JTabbedPane jTabbedPane1 = new javax.swing.JTabbedPane();
JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
JPanel jPanel1 = new javax.swing.JPanel();
JButton jButton1 = new javax.swing.JButton();
JButton jButton2 = new javax.swing.JButton();
JScrollPane jScrollPane2 = new javax.swing.JScrollPane();
JTable jTable1 = new javax.swing.JTable();
Frame.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
jButton1.setText("jButton1");
jPanel1.add(jButton1);
jButton2.setText("jButton2");
jPanel1.add(jButton2);
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object[][]{
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
{null, null, null, null, null, null, null, null, null, null, null, null},
},
new String[]{
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jPanel1.add(jScrollPane2);
jScrollPane1.setViewportView(jPanel1);
jTabbedPane1.addTab("tab2", jScrollPane1);
Frame.setContentPane(jTabbedPane1);
Frame.setVisible(true);
}