English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hello again,

I've asked a few questions regarding how to build a form in Java using AWT. I'm having a lot of problems getting the components to align themselve in a visually appealing way -- for some reason things seem to default to terrible placement.

Anywyas, the form I want is like this:

UserID: [TextBoxHere]
Name: [TextBoxHere]
Status: [DropDownMenuHere]
Language: [CheckBoxHere][CheckBoxHere]...[CheckBoxHere]...
Foreign: [RadioButtonHere] [RadioButtonHere]
[Text box here ]


Now this would be very simple to do in HTML (and I'm sure there must be some trick to doing it in Java, but I can't seem to figure it out) I'm using the GridBagLayout and adjusting the gridx and gridy values as I add the above componets to the applet.

It looks terrible -- labels on the far left of the window, text fields several inches to the right...Radio buttons and checkboxes are spaced irratically -- Help!! :]

2007-08-14 14:13:38 · 4 answers · asked by Tigian 1 in Computers & Internet Programming & Design

4 answers

Are you using the other (align, weight, fill) properties of GridBagConstraints?

If you want the labels column to be narrow, then you'd set its "weightx" to zero. Also set the column for the entry fields to have non-zero "weightx." Then the labels won't get bigger as the window expands -- extra space will be given to the text boxes (etc.) column, and those things won't get too far away from the labels.

If you want the labels inset from the left edge, use a non-zero "insets" value. "insets" is another field on GridBagConstraints.

If you want the labels aligned to the right so that they're up against the input fields that they label, use "anchor" value EAST.

If you want the Radio buttons up against each other, then you can place them in a single JPanel in one grid cell. Or you can add a third vertical column -- but then you'll want to make all the text boxes and things above have gridwidth=2 so that they span both the second and third columns. (Otherwise, the width of the text boxes will push the second checkbox and radio button way off to the right.)

GridBagConstraints has a boatload of options; I do nice-looking GUIs (and especially ones that behave well when the window is resized) all the time, using them.

2007-08-14 14:23:45 · answer #1 · answered by McFate 7 · 0 0

individually i hit upon myself good interior the middle. i do no longer think of that it incredibly is possible to pass approximately your day devoid of having some form of interplay with non-mehrams adult men. My husband and that i as an occasion carry out with married couples, while spending time with them I evaluate it completely ok for him to talk to any of the ladies, he additionally thinks it incredibly is okay for me to talk to any of the adult men interior the Presence of one yet another. i'm no longer speaking approximately flirting in any respect, basically a delightful useful communique. among those human beings there are some that may not shake palms with the different intercourse or talk. while outdoors (mall, keep etc) if i ought to work together with a non-mehram and that i've got faith that he's flirting I on the instant walk away making specific he's conscious why i'm walking away.

2016-10-15 09:02:12 · answer #2 · answered by ? 4 · 0 0

use the BoxLayout, then align all components onto the Y-Axis. you can look at the Box class also which is helpful in box layouts. and the BorderFactory class might be helpful too. and i think the javax.swing package would be easier to use than java.awt.

2007-08-17 03:39:55 · answer #3 · answered by rodette p 3 · 0 0

May I suggest that you try org.jdesktop. layout.GroupLayout
It is way easier to do what you want. It is the default layout used in NetBeans and is automatically included in Java 1.6

To make your job really easy, just use NetBeans to lay it out. Free download from:
http://java.sun.com

2007-08-14 14:28:29 · answer #4 · answered by oldguy 4 · 2 0

fedest.com, questions and answers