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

    Default HOw split the panel in two two halves and add the Action listener to it ....

    Hi ,

    I Need some help on this,

    Here is my Code

    Which contains a tabbed pane and in the sub panel it has two sub panels 1. new user 2.list
    if i click a button in panel --- one new user --- i need to get call a function which is of other class so that it displays the list in the right panel

    As i was not able to fulfil that requirement please help me on this

    ----------------------------
    import java.awt.*;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.*;

    public class Test extends JFrame{

    protected JSplitPane splitpane;

    public void createUI() {


    JTabbedPane tabbedPane = new JTabbedPane();


    JPanel newuser = new JPanel();



    JPanel userdetails = new JPanel(new GridBagLayout());
    //.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);
    submit.addActionListener(
    new ActionListener() {

    @Override
    public void actionPerformed( ActionEvent e) {
    System.out.println("Button pressed.");
    repaint();
    }
    }
    );

    JPanel currentuserlist = new JPanel();
    JTextArea data = new JTextArea("Registered Users\n1\n2\n3\n4\n5\n6\n7\n", 10, 20);
    JScrollPane userPane = new JScrollPane( data );
    currentuserlist.add(userPane);

    splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,userdetails , currentuserlist);
    splitpane.setContinuousLayout(false);
    splitpane.setOneTouchExpandable(true);
    splitpane.setSize(500, 500);

    newuser.add(splitpane, BorderLayout.BEFORE_FIRST_LINE);


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


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

    setVisible(true);
    setSize(700,500);
    setName("ADMIN EXAMPLE");
    }
    public void hello() {

    System.out.println("Hi");

    }


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

    }

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: HOw split the panel in two two halves and add the Action listener to it ....

    Please edit your post and wrap your code with code tags:
    [code]
    YOUR CODE HERE
    [/code]
    to get highlighting and preserve formatting.
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Replies: 4
    Last Post: 03-19-2013, 02:11 PM
  2. Need help with an action listener please
    By ndsmith20 in forum New To Java
    Replies: 3
    Last Post: 03-15-2013, 12:02 AM
  3. action listener
    By skuskusas in forum New To Java
    Replies: 4
    Last Post: 09-04-2012, 07:13 PM
  4. Replies: 2
    Last Post: 12-11-2011, 10:44 PM
  5. Replies: 4
    Last Post: 08-11-2010, 12:47 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
  •