Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Placing a button anywhere  RSS feed

 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I saw that someone in my class use some function to place button anywhere on the frame via x and y corrdinates. He doesn't remember what the function was, does anybody aroud here know?
 
Wayne L Johnson
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm unaware of a "standard" XY-layout manager in Java, though in the past some IDE vendors have created custom layout managers that used a fixed X- and Y-coordinate placement (eg., Borland's JBuilder 8 has an XYLayout class).
The GridBadLayout manager might be contorted to provide this, provided you put everything into the same grid and used GridBagConstraints to provide X- and Y-offsets. I haven't tried it, but it might work.
Actually it's not that hard to create a custom layout, and making an XY-layout manager is a good little exercise.
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
all I know is I saw his code and it went like this:
buttonName.someFunction(x,y);
then I think he added it like normal
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jeremy,
Although it's not recommended, here's what you do: you call setLayout(null) on the container so there's no layout manager at all, add the component, and then call setBounds() to set the component's width, height, and coordinates.
This isn't recommended because it's not portable; a GUI built this way may look fine on one machine but lousy on another, due to differences in screen resolution, window dimensions, etc.
 
Jeremy Jones
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you, that's what it was
I'll keep that in mind thanks
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!