TabbedPanel

stanleyhuen
stanleyhuen used Ask the Experts™
on
hi,
I am using a table model which is almost the same as a jfc example:

http://infodoc.unicaen.fr/docs/Java/jfc.1.0.examples/Table/JDBCAdapter.java

dataBase.executeQuery("select name, qty1, qty2 from table1");

Now I would like to use TabbedPanel, in each Panel in the Tabbed Panel, I have to make a JTable with JDBCAdapter, eg,
dataBase.executeQuery("select name, qty1, qty2 from table1 where conditon = 1");

in the Second Panel,
the JDBCAdpater, dataBase.executeQuery("select name, qty1, qty2 from table1 where conditon = 2");

etc...

I haven't used TabbedPanel before, how to use it to make my work?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Create instances of your JTable and add them to the JTabbedPane like so :

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;

public class JTabs extends JFrame{

     Container contentPane;
     JTabbedPane jtp;
     JPanel jp1, jp2, jp3;
     JLabel jl;

     public JTabs(String args[]){
          super("JTabs");
          this.setDefaultCloseOperation(EXIT_ON_CLOSE);
          contentPane = this.getContentPane();
          contentPane.setLayout(new BorderLayout());
          jtp = new JTabbedPane();
          jp1 = new JPanel();
          jp2 = new JPanel();
          jp3 = new JPanel();
          jtp.addTab("Panel1",jp1);
          jtp.addTab("Panel2",jp2);
          jtp.addTab("Panel3",jp3);
          contentPane.add(jtp,BorderLayout.CENTER);
          jl = new JLabel("Panel1");
          contentPane.add(jl,BorderLayout.SOUTH);
          jtp.addChangeListener(new TabSelectionListener());
     }

     public static void main(String args[]){
          JTabs jt = new JTabs(args);
          jt.setSize(400,400);
          jt.setVisible(true);
     }

     class TabSelectionListener implements ChangeListener{
          public void stateChanged(ChangeEvent e){
               jl.setText("Tab " + jtp.getSelectedIndex() + " selected.");
          }
     }
}
I have used JPanels in palce of your tables.

You can use the tab selection listener to refresh the tables or whatever you want. You might want to put the tables in JScrollPanes too.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial