Jump to content

How to center align all elements inside a jframe to center in java?

Shammikit

Im making a ATM enter PIN screen using java.i have written the code to make it appear full screen when i run it but all the other elements such as the jtextfield,labels and buttons are still at the top left corner of the screen.How can i get them all to the center of my screen? . 

Link to comment
Share on other sites

Link to post
Share on other sites

maybe a dynamic layout? Set its location based on height and width of the frame.

                     ¸„»°'´¸„»°'´ Vorticalbox `'°«„¸`'°«„¸
`'°«„¸¸„»°'´¸„»°'´`'°«„¸Scientia Potentia est  ¸„»°'´`'°«„¸`'°«„¸¸„»°'´

Link to comment
Share on other sites

Link to post
Share on other sites

2 hours ago, vorticalbox said:

maybe a dynamic layout? Set its location based on height and width of the frame.

this is the code that i have used to make it go fullscreen;

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
        setBounds(0,0,screenSize.width,screenSize.height);
        setVisible(true);

i think it adjust height and width according to the screen size of the device.if i assign height and width according to my device and try to view it at a another device with a larger screen it will not align properly like in mine right

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×