Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Java GUI Help

  • 22-02-2005 1: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,305 ✭✭✭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