Reputation: 306
my question is simple but I can not find exact solution for this. I try to write a program with Java GUI, I use absolute layout for my program and I set frame bounds(100, 100, 450, 300) . When I run the program and make it full screen, components stays on their places. I want them to replace automatically according to screen size.
All supports are accepted, thank you!
Upvotes: 4
Views: 316
Reputation: 285405
The solution is quite simple. You state, "I use absolute layout for my program and I set frame bounds(100, 100, 450, 300)."
Don't do this. Use the layout managers to help you place your components.
For instance, if you used a BorderLayout for the main JPanel, and added the JButton to a new GridLayout(0, 1, 0, 5)
using JPanel (1 column, variable rows, 5 spaces between rows), adding this JPanel to main in the BorderLayout.LINE_END position, your problem is likely solved. As a general rule, you should avoid use of null layout and use of setBounds(...)
for component placement as this makes for very inflexible GUI's that while they might look good on one platform look terrible on most other platforms or screen resolutions and that are very difficult to update and maintain.
Upvotes: 6