Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help me with Java UID

Status
Not open for further replies.

LovelyAngel

Programmer
Mar 17, 2002
17
0
0
GB
Hi all,

Do you guys know how to put a component such as a button to a specified position on a panel, for example position (100, 100, 150, 150).

Thank you very much
 
Create JPanel and set is LayoutManager to null
Code:
 setLayout(null);

This will stop Java trying to place each componenet, then you can use the
Code:
setBounds
code available to all Gui components to place the button excately where you want it and at what size you want.

-----------------
setBounds

public void setBounds(int x,
int y,
int width,
int height)

Moves and resizes this component. The new location of the top-left corner is specified by x and y, and the new size is
specified by width and height.

Parameters:
x - the new x-coordinate of this component
y - the new y-coordinate of this component
width - the new width of this component
height - the new height of this component
Since:
JDK1.1
See Also:
getBounds(), setLocation(int, int), setLocation(Point), setSize(int, int),
setSize(Dimension)
----------------------------

careful though, doing this will mean that if you resize the window, it will stay in the same place, it will not readjust like it would witha layout manager. ----------------------------------------
There are no onions, only magic
----------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top