I need to create a login interface that opens in full screen(working in all display resolutions) but with undecorated(true). I could create the expected jframe but how can i position swing components in the center of the jframe? here is what I need to get https://drive.google.com/file/d/0B3-1tpHz8_TGU1p3SlA2UGMxekk/edit?usp=sharing and this is adaptive to all screen sizes
Asked
Active
Viewed 1,585 times
1
-
For this use BorderLayout and assign the alignment to CENTER of Swing components. – Girish K Mar 01 '14 at 10:12
-
@NadunLiyanage Totally unrelated to this question, you deleted your recent question before I could answer it. Set the container background to `null` to revert to inherited default. Sorry about hijacking this question. – Jason C Mar 03 '14 at 18:00
-
Thank you very much mr Jason...I did the same thing you said... it was working again thank you so much for your feedback.... and im sorry for the inconvenience caused... – Nadun Liyanage Mar 04 '14 at 14:34
3 Answers
3
An undecorated frame is still a frame. In fact you could simply use a JWindow
.
What this means is, decorated or otherwise, you can layout your components as per normal. Because your pushing for full screen, I might suggest using something like GridBagLayout
as a bases, but that's me.

MadProgrammer
- 343,457
- 22
- 230
- 366
-
Thank you for your quick responses... Here Im new in java and I think that the question was not clear... Here is the thing I need to do. https://drive.google.com/file/d/0B3-1tpHz8_TGU1p3SlA2UGMxekk/edit?usp=sharing ![enter image description here][1] – Nadun Liyanage Mar 01 '14 at 10:33
-
Yes, and. This seems simple enough for GridBagLayout to a eve quite well – MadProgrammer Mar 01 '14 at 20:09
0
use the setBounds() method
setLayout(null);
setBounds(int x,int y,int width,int height);
setBounds() method will place the components in the desired position of the JFrame window.

Balayesu Chilakalapudi
- 1,386
- 3
- 19
- 43
-
2In 15 years of professional Swing development, I never found a reason to use a null layout, a given the problems of font metrics, dpi and other rendering differences between platforms makes this a incredibly difficult and error prone solution - just saying – MadProgrammer Mar 01 '14 at 09:59
-
1*"use the setBounds() method"* ..unless of course, you want a *reliable and robust* GUI. Java GUIs might have to work on a number of platforms, on different screen resolutions & using different PLAFs. As such they are not conducive to exact placement of components. To organize the components for a robust GUI, instead use layout managers, or [combinations of them](http://stackoverflow.com/a/5630271/418556), along with layout padding & borders for [white space](http://stackoverflow.com/q/17874717/418556). – Andrew Thompson Mar 01 '14 at 10:15
0
Use Border Layout,This layout will help you to assign components to center.
For example:`
Frame.add(GuiFieldsPanel, BorderLayout.CENTER);
Or
Frame.add(GuiButtonsPanel, BorderLayout.CENTER);
Frame.setVisible(true);

Girish K
- 758
- 1
- 13
- 24
-
In your second line `GuiButtonsPanel` will replace `GuiFieldsPanel` at `BorderLayout.CENTER` position. `BorderLayout` can lay out just a single component in each location. – dic19 Mar 01 '14 at 16:00
-
NorderLayout will only allow a a single component to occupy any one of its 5 available positions, this means, you can't have to two components occupying the CENTER position – MadProgrammer Mar 01 '14 at 20:01
-
Ohh..sorry for mistake.i will correct the answer..thanks for suggestion. – Girish K Mar 02 '14 at 05:29