tags:

views:

259

answers:

3

I have some JButtons in a JFrame. The layout of JFrame is null. i have given absolute position to button. But when i minimize or maximize frame, the postion of the buttons is getting disturbed how can i set it relative to JFrame dynamically?

+1  A: 

Write your own layout. Otherwise, you'll be doing the same thing, just with a mess of listener classes.

McDowell
ok i will look for my own layout manager... thanks
Mandar
A nice example, StarLayout, may be found here: http://mindprod.com/jgloss/starlayout.html
trashgod
+1  A: 

Use a layout manager. This is the kind of issue that they are designed to handle automatically.

As others have said, writing your own absolute layout manager is the best way to handle this. Alternatively, you could look at Explicit Layout to see if it meets your needs. There are also references on the web to an AbsoluteLayout class that either does or used to come with Netbeans. Perhaps you could track that down and use it.

Mark
but i want positioning absolute
Mandar
Is there any real reason you need to absolute position buttons? Could you not use a more advanced layout manager like MigLayout or JGoodies Forms? Otherwise, the best way to go is to write your own absolute layout manager to handle these issues.
Mark
i don't know about advanced layout managers. have to look at it
Mandar
+1  A: 

Another option from the Java Tutorial:

http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html

I know that in a project I was working on, we needed to do absolute positioning, so we actually made our own Layout (which we called an absolute layout) and passed in constraints to it (which we called the absolute constraints).

Edit: As noted by others, I would recommend using a layout manager unless there is a good reason for absolute positioning. GridBagLayout is a commonly used one, and I have found it to be the best as long as you follow the standards. The java tutorial for it is here:

http://java.sun.com/docs/books/tutorial/uiswing/layout/gridbag.html

aperkins
good advice thanks i will look in the link
Mandar