• Post Reply Bookmark Topic Watch Topic
  • New Topic

JButton and setLocation()  RSS feed

 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i use setLocation in my code, and it changes the X and Y of the component..

but the component still gets added to the JPanel in a FlowLayout manner

why is this?

is there a different add method to use?

i just want to change the positions of my JButtons..

thanks,

Justin
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A LayoutManager will put components wherever it wants to.

If you insist on setting the coordinates yourself, then you have to get rid of the LayoutManager altogether using "setLayout(null)" on the container.
 
Justin Fox
Ranch Hand
Posts: 802
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i did that, none of the buttons showed up


Justin
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you call setLayout(null), then it's your responsibility to set the location and dimensions of every component; this is often done using "setBounds()". So if you want a 10x20 button at location 100, 200, then you'd call "setBounds(100, 200, 10, 20)" on your button.
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This ought to go to Swing/AWT. Moving...
 
steijn bouman
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you have to set the size of the jButton by

jbutton.setSize(100,100);

but you also can try the netbeans JFormDesigner
 
Kocha Sapam
Ranch Hand
Posts: 35
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Agree with ernest friedman, i do just that (and i've made my jframe unresizeable)
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!