Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java GUI Help

  • 22-02-2005 02:58PM
    #1
    Closed Accounts Posts: 3,105 ✭✭✭


    This should be really easy to fix.. but i don't know how to do it...

    I'm doing up a class that extends JFrame
    i'm using
    panel.setLayout(new BorderLayout());
    
    and then i stick buttons on it:
    panel.add(BorderLayout.NORTH, input);
    
    but i want the button layout to have rows of buttons like in an Applet GridLayout thing.. i haven't gotten the GridLayout Function to work with the code i have maybe i've done it wrong or maybe it can't be done.. i don't know anyway...

    QUESTION: how will i code the row of buttons does anyone have some sample code that i can look at?

    THANKS


Comments

  • Registered Users, Registered Users 2 Posts: 3,312 ✭✭✭irishguy


    if i understand you right you need 2 panels. Create a JButtenpanel with grid layout then add the JButtenpanel to your other panel.have a look below

    public void init () {

    JPanel textPanel = new JPanel();
    textPanel.setLayout(new GridLayout(4,1));

    Container c = getContentPane();

    c.setLayout(new FlowLayout(FlowLayout.RIGHT));

    //Setup Text panel
    employeeNo = new JTextField(20);
    textPanel.add(employeeNo);

    firstName = new JTextField(20);
    textPanel.add(firstName);

    lastName = new JTextField(20);
    textPanel.add(lastName);

    age = new JTextField(20);
    textPanel.add(age);

    c.add(textPanel,BorderLayout.WEST);

    outputArea = new JTextArea(25,40);
    outputArea.setEditable( false );
    JScrollPane scroller = new JScrollPane(outputArea);
    c.add( scroller );

    //setup button panel

    JPanel buttenPanel = new JPanel();
    buttenPanel.setLayout(new GridLayout(1,5));

    jbInsert = new JButton("INSERT");
    buttenPanel.add(jbInsert);
    jbInsert.addActionListener(this);

    jbDelete = new JButton("DELETE");
    buttenPanel.add(jbDelete);
    jbDelete.addActionListener(this);

    jbSearch = new JButton("SEARCH");
    buttenPanel.add(jbSearch);
    jbSearch.addActionListener(this);

    jbQSize = new JButton("Q SIZE");
    buttenPanel.add(jbQSize);
    jbQSize.addActionListener(this);

    jbFront = new JButton("FRONT");
    buttenPanel.add(jbFront);
    jbFront.addActionListener(this);

    c.add(buttenPanel,BorderLayout.SOUTH);


    }


Advertisement