|
-
October 9th, 2009, 03:32 PM
#1
Using Swing and Placing Components
..how difficult can this really be.
I'm having so much trouble placing my components on my "frame" that it is making my head. I don't understand all the different layouts, and I heard GridBagLayout is the better one to use. Using GridBag, I can't put a component to the top, others near the middle of the frame, and my button on the bottom right. The coordinate system is just not working the way I want.
Is there another layout where I can say "put this button at x=780, y=800" while I have the bulk of my components near a x=400, y=300 coordinate area?
I think I need some basic help, or some helpful examples, or something... I would like to do this without a visual editor plugin, but I didn't except all this trouble I'm having.
Can you help/suggest anything?
-= the best is yet to come =-
-
October 9th, 2009, 04:38 PM
#2
Re: Using Swing and Placing Components
why don't you do null..you can put everything where you want..
Please use code tags like this : [SIGPIC][/SIGPIC]
Code Your Dreams 
-
October 9th, 2009, 05:43 PM
#3
Re: Using Swing and Placing Components
Have you read this:
http://java.sun.com/docs/books/tutor...ybigindex.html
...specifically the section 'Creating a GUI With JFC/Swing -> Laying Out Components Within a Container'?
-
October 9th, 2009, 05:59 PM
#4
Re: Using Swing and Placing Components
As Holestary said, if you set a null layout, you can place components by co-ordinate, but this is generally considered to be a Bad Idea, because it doesn't scale, takes a lot of work, and is a nightmare to maintain or change.
It's well worth learning to select and use layouts. See Using Layout Managers
I hear and I forget; I see and I remember; I do and I understand...
Confucius
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
-
October 12th, 2009, 03:28 PM
#5
Re: Using Swing and Placing Components
... the text at Sun for me isn't that well explained. I did look throughout and still didn't get a good feeling after reading/trying it. Like, is the document saying I shouldn't manually code by hand when using a Layout Manager instead use a tool ie. NetBeans IDE?
I would like to use GridBagLayout since it is so flexible (despite it being so complex), but I can't get it the exact way I want. I want my grid's origin to start at the top-left on my panel; how do I get it there? The borderlayout doesn't have a setting for that.
-= the best is yet to come =-
-
October 12th, 2009, 06:25 PM
#6
Re: Using Swing and Placing Components
 Originally Posted by capitolc
Can you help/suggest anything?
Have you checked out the Swing pages at Sun?
http://java.sun.com/docs/books/tutor...ing/index.html
Maybe you're rushing it? You need to start small and go from there.
Last edited by nuzzle; October 12th, 2009 at 10:25 PM.
-
October 14th, 2009, 07:46 AM
#7
Re: Using Swing and Placing Components
 Originally Posted by capitolc
I would like to use GridBagLayout since it is so flexible (despite it being so complex), but I can't get it the exact way I want. I want my grid's origin to start at the top-left on my panel; how do I get it there? The borderlayout doesn't have a setting for that.
If you can explain exactly how you want to layout your panel (a picture would help), maybe we can suggest some ways to do it.
Layout managers take a while to become familiar with, but it pays off in the long run. Don't forget that you can put panels inside panels and use different layout managers for each.
Plan to throw one away; you will anyhow...
F. Brooks
Please use [CODE]...your code here...[/CODE] tags when posting code. If you get an error, please post the full error message and stack trace, if present.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|