How to set the X,Y position of button in frame?

21,504

Solution 1

can any one tell me the property to set the button position on the Jframe.

answer is simple --->

use proper Layout Manager, in the case that you'll real question edit with description but SSCCE will be better

Solution 2

If you have an Absolute Layout (which you must not, horrible resizing capabilities, and a bad habit), you can call on either .setBounds(int x, int y, int w, int h), or .setLocation(int x, int y).

Share:
21,504
Admin
Author by

Admin

Updated on July 22, 2020

Comments

  • Admin
    Admin almost 4 years

    How to set the JButton position on the JFrame?

  • Hidde
    Hidde almost 12 years
    Not a real answer to the question the OP is asking, although it is not asked nicely.
  • Hidde
    Hidde almost 12 years
    Whoops, it's .setLocation (int x, int y). Again, you should use a LayoutManager, and not an Absolute Layout unless you really must.
  • Andrew Thompson
    Andrew Thompson almost 12 years
    @Hidde I don't think an absolute layout is a real answer to any need. Layouts, using appropriate layout padding, and occasional empty borders, is a much better way to logically layout a GUI that includes white-space. Try recreating something like the Nested Layout Example (including PLAF change) using an absolute layout (and a ComponentListener presumably).
  • Hidde
    Hidde almost 12 years
    I agree that you almost never use an Absolute Layout, but I have found use for it once (a small math application with drawings in which buttons were placed. I had to make it unresizable...). Here however, the OP asks for a way to put his button in a NULL Layout, so that's the answer I give him, with further advice.