Results 1 to 5 of 5
  1. #1
    harish516 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Post Panels and Layouts In Swings

    Hi All,

    I am struggling to get the the Tabbed Panel
    Which has
    1)two sub panels each one on left and one on the right
    And i need to get one event performed like if i click on the submit button i need to get a list on the right hand side in one panel

    Can any one please help me out to resolve this issue


    Here is
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.text.GapContent;


    public class Example extends JFrame
    {
    JTabbedPane tabbedPane = new JTabbedPane();

    JPanel dividescreen = new JPanel( new BorderLayout());
    JPanel newuser = new JPanel( new FlowLayout(20, 20, 12));
    JPanel userlist = new JPanel( new FlowLayout(20, 20, 12));
    JPanel quit = new JPanel( new FlowLayout(20, 20, 12));
    JTextArea data = new JTextArea("Registered Users\n1\n2\n3\n4\n5\n6\n7\n8\n9\n1\n2\n3\n4\n5\n6 \n7\n8\n9\n0\n", 3, 40);
    JScrollPane newUseruserPane = new JScrollPane( data );
    JButton submit = new JButton("SUBMIT");
    /**
    * @param args
    */
    public Example()
    {
    super ("TabbeLayout Demo");
    setBounds(250, 250, 800, 300);

    JPanel newuserfullname = new JPanel( new GridLayout(1, 3));
    newuserfullname.add(new JLabel(" Full Name"));
    newuserfullname.add(new JLabel(" "));
    newuserfullname.add(new JTextField(" ", 10));


    JPanel newusername = new JPanel( new GridLayout(1, 0));
    newusername.add(new JLabel(" Logon Name"));
    newusername.add(new JLabel(" "));
    newusername.add(new JTextField(" ", 10));


    JPanel newuserpword = new JPanel(new GridLayout(1, 0));
    newuserpword.add(new JLabel(" Password"));
    newuserpword.add(new JLabel(" "));
    newuserpword.add(new JTextField(" ", 10));

    submit.setPreferredSize(new Dimension(10, 10));

    newuser.add(newuserfullname);
    newuser.add(newusername);
    newuser.add(newuserpword);
    newuser.add( submit);

    //----------------------------


    dividescreen.add(newuser,"West");
    dividescreen.add(newUseruserPane, "Center");


    tabbedPane.addTab( "NewUser", dividescreen);
    tabbedPane.addTab( "Quit", quit);

    Container pane = getContentPane();
    pane.add(tabbedPane, BorderLayout.CENTER);
    setVisible(true);
    }

    public static void main(String[] args) {

    Example demo = new Example();
    demo.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE );
    }

    }

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default Re: Panels and Layouts In Swings

    What about this is giving you trouble?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    harish516 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Panels and Layouts In Swings

    I am not able to create the panels as required.............

    Tabbed Panel
    first panel
    second Pannel

    1)two sub panels of the first panel
    which has some buttons on the left hand side and the Right hand side panel has some text....

    Please help me out in this

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is offline Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,958
    Rep Power
    8

    Default Re: Panels and Layouts In Swings

    Okay, but why aren't you able to do that? What specifically are you confused about?
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    harish516 is offline Member
    Join Date
    Mar 2014
    Posts
    4
    Rep Power
    0

    Default Re: Panels and Layouts In Swings

    HERE IS MY CODE THAT I USED TO CREATE:

    import java.awt.*;

    import javax.swing.*;

    public class Test extends JFrame{

    protected JSplitPane m_sp;

    public void createUI() {


    JTabbedPane tabbedPane = new JTabbedPane();


    JPanel newuser = new JPanel();



    JPanel userdetails = new JPanel(new GridBagLayout());
    //frame.getContentPane().add(userdetails, BorderLayout.PAGE_START);

    GridBagConstraints c =new GridBagConstraints();

    JLabel fullname=new JLabel("FULL NAME");
    c.gridx=0;
    c.gridy=0;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(fullname,c);

    JLabel logonname=new JLabel("LOGON NAME");
    c.gridx=0;
    c.gridy=1;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(logonname,c);


    JLabel password=new JLabel("PASSWORD ");
    c.gridx=0;
    c.gridy=2;
    userdetails.add(password,c);


    JLabel repeatpassword=new JLabel("REPEAT PASSWORD ");
    c.gridx=0;
    c.gridy=3;
    userdetails.add(repeatpassword,c);


    JTextField fname = new JTextField(12);
    c.gridx=1;
    c.gridy=0;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(fname,c);

    JTextField lname = new JTextField(12);
    c.gridx=1;
    c.gridy=1;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(lname,c);

    JTextField pword = new JTextField(12);
    c.gridx=1;
    c.gridy=2;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(pword,c);

    JTextField repeatpword = new JTextField(12);
    c.gridx=1;
    c.gridy=3;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(repeatpword,c);

    JButton submit = new JButton("SUBMIT");
    c.gridx=0;
    c.gridy=4;
    c.insets = new Insets(10, 10, 10, 10);
    userdetails.add(submit,c);


    JPanel c12 = new JPanel();



    m_sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,userdetails , c12);
    m_sp.setContinuousLayout(true);
    m_sp.setOneTouchExpandable(true);

    newuser.add(m_sp, BorderLayout.CENTER);


    JPanel quit = new JPanel();
    tabbedPane.addTab( "New User", newuser);
    tabbedPane.addTab( "Quit", quit);


    Container pane = getContentPane();
    pane.add(tabbedPane, BorderLayout.CENTER);

    setVisible(true);
    setSize(500,500);
    }

    public static void main(String[] args) {
    Test se = new Test();
    se.createUI();
    }

    }
    Last edited by harish516; 03-04-2014 at 10:17 PM.

Similar Threads

  1. Layouts
    By tnrh1 in forum AWT / Swing
    Replies: 3
    Last Post: 12-06-2011, 08:00 PM
  2. Need some help with panels inside panels
    By kakefjes in forum AWT / Swing
    Replies: 0
    Last Post: 03-17-2011, 11:36 AM
  3. Java Panels and Layouts help
    By Zookey in forum New To Java
    Replies: 2
    Last Post: 01-30-2011, 12:06 PM
  4. Problem while using the multiple panels in swings
    By anand206 in forum AWT / Swing
    Replies: 3
    Last Post: 03-23-2010, 04:33 PM
  5. Layouts ?
    By plodos in forum Eclipse
    Replies: 3
    Last Post: 07-30-2007, 03:03 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •