Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Gridlayout buttons in a BorderLayout frame.

$
0
0
I want the 4 buttons to be placed on the bottom left of the frame, but currrently it fills up the whole bottom borderlayout of the frame.

Is there any method to not fill up the whole bottom borderlayout and only fill up the left portion and increase the height of the buttons itself ?

image of output

import javax.swing.*;      
import java.awt.*;

public class Puzzle extends JFrame {
    
    public Puzzle(){
        // sets size of frame
        this.setSize(1300,650);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("JPRG Assignment");
        this.setVisible(true);
        // forces frame to remain in the center of the screen 
        this.setLocationRelativeTo(null);
        
        // create a new panel - panel1
        JPanel panel1 = new JPanel();   
        this.add(panel1,BorderLayout.SOUTH);
        // set layout of panel1
        panel1.setLayout(new GridLayout(2,2));
        
        // create new buttons - button1 to button4
        JButton button1  = new JButton("Start Game");
        JButton button2  = new JButton("Get History");
        JButton button3  = new JButton("Reset Game");
        JButton button4  = new JButton("Exit Game");
        
        // adds button1 to button4 to panel1
        panel1.add(button1);
        panel1.add(button2);
        panel1.add(button3);
        panel1.add(button4);
    }
}


Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>