Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / GUI / December 2007

Tip: Looking for answers? Try searching our database.

Setting z-index in Swing & adding components

Thread view: 
Mohammad Javad Dousti - 28 Dec 2007 22:37 GMT
Hi,
1-I'm using absolute layout in Java. I want to set the z-index of my
component after adding them. How can I do so?
2-How can I get the X and Y of an added component in absolut layout?

BTW: I'm using JDK 1.6u2 with NetBeans 6.0. The absolute layout
address is:
new org.netbeans.lib.awtextra.AbsoluteLayout()

Thanks for your help.
Andrew Thompson - 29 Dec 2007 04:51 GMT
...
>1-I'm using absolute layout ..

Why? *

> ..in Java.

Using absolute layouts is a bad idea in an X-plat,
X-plaf, multi-VM language.

>..I want to set the z-index of my
>component after adding them.

* What is this GUI that requires absolutely positioned,
overlapping components?  Some types of GUIs might be
better suited to a CardLayout that shows any one GUI
element (usually a panel with many other panels and
widgets inside it) a JTabbedPane or a JDesktopPane.

>..How can I do so?

Why do you want to do so?

>2-How can I get the X and Y of an added component in absolut layout?

One way would be to remember where you absolutely
placed it in the first place (I would guess).  But also,
you might try these methods listed in the JavaDocs
java.awt.Component.getLocation(java.awt.Point)
(as well as getX(), and getY() ).

Signature

Andrew Thompson
http://www.physci.org/

Mohammad Javad Dousti - 29 Dec 2007 05:47 GMT
> ..
>
[quoted text clipped - 32 lines]
>
> Message posted viahttp://www.javakb.com

Because no other layout can do my work. I want to design a board game:
put the places as JButton and the player as another JButton and put it
on the places. But the arrangement of places is very specific! (Take a
look at http://en.wikipedia.org/wiki/Monopoly_(game))
As I said, the component doesn't know its X and Y (So we can't use
getX and getY)
Andrew Thompson - 29 Dec 2007 07:53 GMT
>> ..
>>
>[quoted text clipped - 32 lines]

Please learn how to post in-line with trimming.
...
(Why AbsoluteLayout?)

>Because no other layout can do my work.

Rot.  Whatever cannot be done in any single layout is
pretty simple to achieve with nested layouts.

>..I want to design a board game:
>put the places as JButton ..

JButtons do not make sense for the game place squares
themselves, though perhaps as a D'n'D (Drag'n'Drop, as
opposed to Dungeons and Dragons) DropTarget - probably
implemented on a (custom) BoardPlacePanel that has a
custom background, and is itself contained in a larger
layout.*

>..and the player as another JButton and put it
>on the places. But the arrangement of places is very specific!

*All* Java Layouts are very specific, and are also
very adaptive to the size and shape of the underlying
components.  Lock down the size of the underlying
components, and the overall layout and size can
also be locked.

>..(Take a
>look at http://en.wikipedia.org/wiki/Monopoly_(game))

Monopoly, ..yes I'm familiar with it.  Please enclose
URLs in <>, to help prevent line wrap and incorrect parsing.
..look at <http://en.wikipedia.org/wiki/Monopoly_(game)>)

* Use a GridLayout for each of the four sides, around the
borders of a BorderLayout.  Drop a GridBagLayout in the
CENTER for the game cards, dice etc. D'n'D should be
able to handle the rest.

You might be able to do the entire GUI in a GBL,
here is a Periodic Table implemented in a* GBL.
<http://physci.org/jnlp/PToE.jnlp>
* Though their are some other layouts, and HTML
formatting, thrown in for good measure.

>As I said, the component doesn't know its X and Y (So we can't use
>getX and getY)

I find that hard to believe.  What results when you call ? ..
 System.out.println( myGamePieceJButton.getX() );

Signature

Andrew Thompson
http://www.physci.org/

Chase Preuninger - 30 Dec 2007 20:10 GMT
I think there is such thing as JLayerd pane or something that does
that.


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.