Valhalla Legends Forums Archive | Java Programming | Best way to do this GUI layout

AuthorMessageTime
bethra
Ok, so I'm planning on writing a GUI for this program that I'm making and I need some advice on how I should do the layout.

I don't really have much experience with doing GUI in Java.  When I took AP Comp Science the Java textbook we used had us use this "BreezySwing" custom GUI class that it had pre-made and come with on CD.  The problem is that it really was limited on how customizable you could make GUI with it.

So now I'm planning on doing my GUI not using this very limited GUI class and instead use the actual various Java GUI API classes and stuff.

Now, reading through some stuff I saw that there are various Layout Managers you can use like BoxLayout, GridLayout, GridBagLayout, SpringLayout, etc.  Since some of you are more experienced with doing GUI in Java I need some advice on what kind of layout I should use.

Here is a rough draft picture showing kind of what I want the GUI to be like:
[img]http://www.filefarmer.com/mds820/GUILayout.gif[/img]

TF = Text Field
Btn = Button



Thanks.
September 19, 2005, 12:30 AM
The-FooL
It's been awhile since I've done Java GUIs, but I think what you will want to do is use nested JPanels.  I've only used BorderLayout and GridLayout, but I'm sure with a little research you can discover how the others work.  Then create one main layout, add panels to it, then add layouts to the panels, etc.. so that your components come out the way you want.  It will probably take some fiddling to get it right.

For example, you could make the main layout a GridLayout, and add a left and right panel.  To the left panel, you set it to a BorderLayout, add the label to North, the list to Center, and another panel(which has two buttons) to south. 

This is only the way I know how to do it, there may be better ways.
September 19, 2005, 3:13 AM
Dynobird
Yea, BorderLayout is good. Or you could use visual editors provided by IDE's such as NetBeans or Eclipse and others I don't know about. As a rule, programmers shouldn't waste much time on GUI's. If you're using visual editors, the one thing you have to do for yourself (code-wise) is decide all the entry points to your GUI.

For example, in a battle.net bot you make a display area of all the text that you've sent and received. You make this text area component static, so it's the same for all objects, and make a static method that adds new text and perhaps another one that retrieves text. So, for instance, if you're sending all of your packets internally through the class you created for that specific packet, and you want it to display text on your text screen "packet 0x50 sent" etc, then you don't have to instantiate or extend the GUI's class and don't have to worry about passing the text input object via constructors etc. etc.

But if you're just having a simple input, with a button that submits it, then you don't have to worry much about the entry points to your GUI.
October 11, 2005, 9:46 PM

Search