Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Placing a button anywhere

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 399
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thank you, that's what it was
I'll keep that in mind thanks
 
That's my roommate. He's kinda weird, but he always pays his half of the rent. And he gave me this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic