我想使用jtabbedpane来显示一些表(每个选项卡中有一个表)。很容易实现:你做一个jtabbedpane,放一些滚动窗格(代表标签),然后你只需将表添加到滚动窗格中。我的问题是,在滚动窗格中,您只能添加表,我还需要添加文本框、单选按钮和标签。我想知道是否有其他的替代方法。
wgxvkvu91#
如果我理解你。。。您可以将scrollpane放到选项卡并添加到面板中,然后将所需的控件和表添加到面板中;就像这张照片上一样您可以使用jformdesiner来生成代码
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);
2skhul332#
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); }
2条答案
按热度按时间wgxvkvu91#
如果我理解你。。。您可以将scrollpane放到选项卡并添加到面板中,然后将所需的控件和表添加到面板中;
就像这张照片上一样
您可以使用jformdesiner来生成代码
2skhul332#