Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: tabbed panes

  1. #1
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default tabbed panes

    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
     
    public class BaseTab extends JFrame implements ActionListener
    {
    JButton ok;
     JLabel label1;
    JTextField  text1;
        JTabbedPane jt;
        JPanel p7,p1,p2,p3,p4,p5;
        JMenuBar mb=new JMenuBar();
    	JMenu lg=new JMenu("Logout");
       	JMenu hm=new JMenu("Home");
    BaseTab()
    {
        //window appearence
          setTitle("BaseTab");
          setSize(this.getMaximumSize());
          setDefaultCloseOperation(EXIT_ON_CLOSE);
          setVisible(true);
          setJMenuBar(mb);
          mb.add(hm);
          mb.setSelected(hm);
          mb.add(Box.createHorizontalGlue());	
          mb.add(lg);
     
          p7=new JPanel();
         p7.setPreferredSize(new Dimension(1600,1450));
          p7.setLayout(new BorderLayout()); 
          getContentPane().add(p7);
        createPage();
     
          jt=new JTabbedPane();
         jt.addTab("CREATE",p1);
          jt.addTab("INSERT",p2);
          jt.addTab("UPDATE",p3);
          jt.addTab("VIEW",p4);
         p7.add(jt,BorderLayout.CENTER);
     
    }
     
    public void createPage()
    {
    label1 = new JLabel();
    label1.setText("TableName");
    text1 = new JTextField(15);
    ok=new JButton("ok");
    p1=new JPanel();
    p1.setLayout( null );
    p1.add(label1);
     p1.add(text1);
     p1.add(ok);
    p1.setLayout(new FlowLayout());
    setLayout(new FlowLayout());
    ok.addActionListener(this);
    }
     
     public void actionPerformed(ActionEvent ae)
    {
     
       if(ae.getActionCommand()=="ok")
         {
      String value1=text1.getText();
     if (value1.equals("cse")) 
      {
    /* here exits my problem that i need to get components of sacreate page when create tab is clicked*/
        sacreate page=new sacreate();
       page.add(p1);
    }
    }
    }
     
     
    public static void main(String args[])throws Exception
        {
     
          SwingUtilities.invokeLater(new Runnable()
          {
              public void run()
              {
                  BaseTab bt=new BaseTab();
              }
          } );
        }
     
    }


  2. #2
    Junior Member
    Join Date
    Jan 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: tabbed panes

    will u please upload the sacreate code..and what is exactly sacreate? is it other java file??

  3. #3
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: tabbed panes

    import javax.swing.*;
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    class sacreate extends JFrame implements ActionListener
    {
     
    JLabel l1,l2,l3,l4,a,b,c;
    Container pane;
    JPanel p1,p2,p3;
    JTextField t1;
    JComboBox c1,c2;
    JCheckBox m1;
    JButton b1,b2,b3,back;
    public sacreate()
    {
    JButton jb=new JButton("back");
    pane.add(jb);
    pane=getContentPane();
    l1=new JLabel("FieldName"); 
    a=new JLabel("                                       ");
    l2=new JLabel("DataType");
    b=new JLabel("                 ");
    l3=new JLabel("NotNull");
    c=new JLabel("        ");
    l4=new JLabel("Null");
    t1=new JTextField(15);
    c1=new JComboBox();
    c1.addItem("VARCHAR");
    c1.addItem("INTEGER");
    c1.addItem("CHARACTER");
    c2=new JComboBox();
    c2.addItem("PrimaryKey");
    c2.addItem("ForignKey");
    m1=new JCheckBox();
    b3=new JButton("Done");
    b1=new JButton("+");
    b2=new JButton("-");
    p1=new JPanel();
    p2=new JPanel();
    p3=new JPanel();
    p1.add(l1);
    p1.add(a);
    p1.add(l2);
    p1.add(b);
    p1.add(l3);
    p1.add(c);
    p1.add(l4);
    p2.add(t1);
    p2.add(c1);
    p2.add(c2);
    p2.add(m1);
    p2.add(b3);
    p2.add(b1);
    p2.add(b2);
    p3.add(p1);
    p3.add(p2);
    pane.add(p3);
    p1.setLayout(new FlowLayout(FlowLayout.LEFT));
    p2.setLayout(new FlowLayout(FlowLayout.LEFT));
    p3.setLayout(new BorderLayout());
    p3.add(p1,BorderLayout.NORTH);
    p3.add(p2,BorderLayout.SOUTH);
    setLayout(new FlowLayout());
    b1.addActionListener(this);
    b2.addActionListener(this);
    }
     
    public void actionPerformed(ActionEvent ae)
      {
    if(ae.getActionCommand()=="back")
    {
    java.awt.EventQueue.invokeLater(new Runnable() {
     
            public void run() {
     
           new BaseTab().setVisible(true);
            }
        });
     
        }
     JTextField t;
     JComboBox m,n;
     JCheckBox c;
     JButton o,r,q;
     JPanel p;
    p = new JPanel();
    Dimension size=p.getSize();
    //System.out.println(size);
    p.setPreferredSize(new Dimension(1600,35));
    t=new JTextField(15);
    m=new JComboBox();
    m.addItem("VARCHAR");
    m.addItem("INTEGER");
    m.addItem("CHARACTER");
    n=new JComboBox();
    n.addItem("PrimaryKey");
    n.addItem("ForignKey");
    c=new JCheckBox();
    o=new JButton("Done");
    r=new JButton("+");
    r.addActionListener(this);
    q=new JButton("-");
    q.addActionListener(this);
    if(ae.getActionCommand()=="+")
    {
    pane.add(p);
    p.add(t);
    p.add(m);
    p.add(n);
    p.add(c);
    p.add(o);
    p.add(r);
    p.add(q);
    p.revalidate(); 
    p.setLayout(new FlowLayout());
    }
    if(ae.getActionCommand()=="-")
    {
    p.remove(t);
    p.remove(m);
    p.remove(n);
    p.remove(c);
    p.remove(o);
    p.remove(r);
    p.remove(q);
    pane.remove(p);
    p.revalidate();
    p.repaint();
    pane.revalidate();
    }
    }
    public static void main(String args[]) 
    {
     
    SwingUtilities.invokeLater(new Runnable() 
    {
    public void run() 
    {
    sacreate a=new sacreate();
    a.setSize(400,300);
    a.setVisible(true);
    a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    a.setLocationRelativeTo(null);
    }
    });
    }
    }


    --- Update ---

    when i press create tabbed pane the sacreate components must be displayed on the panel....

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: tabbed panes

    Do you get any error messages when you execute the program? Copy the full text and paste it here.

    Please format the code by adding spaces for nested statements. All statements should not start in the first column.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Inserting scroll lists and text fields into tabbed panes
    By Ace Java 9000 in forum AWT / Java Swing
    Replies: 3
    Last Post: January 5th, 2012, 02:12 PM
  2. Reusing Panel code in each tabs on a tabbed pane
    By kurt-hardy in forum Object Oriented Programming
    Replies: 4
    Last Post: March 23rd, 2011, 08:21 AM