I have a picture made by a friend and my job is to insert some java swing components (JLabel, JTextField and JButton)
at first I thought of using FlowLayout
or BoxLayout
, but the components aren't aligned
then I thought about using GridLayout
, but all the components take the same size and don't fit the image anymore
so is there a better way to chose at what pixels should I add my components?
Asked
Active
Viewed 253 times
-2

plase
- 361
- 1
- 3
- 9

Ghassen Tounsi
- 38
- 8
-
*"don't fit the image"* Show the image. More generally: Provide ASCII art or a simple drawing of the *intended* layout of the GUI at minimum size, and **if resizable,** with more width and height - to show how the extra space should be used. – Andrew Thompson Jun 09 '18 at 04:09
-
Use a custom `JPanel` to [draw the image on its background](https://stackoverflow.com/questions/19125707/simplest-way-to-set-image-as-jpanel-background). Assign a layout manger to the custom `JPanel` and use it as you would use any standard `JPanel`. – c0der Jun 09 '18 at 04:13
1 Answers
-1
It seems you'd like to do absolute positioning of your layout. I'm not entirely sure of your usecase, but if you want pixel perfect placement, why not skip using a layout manager and use Absolute Positioning ?

Erik Pragt
- 13,513
- 11
- 58
- 64