[java] Text uitlijnen (gridbaglayout)

Pagina: 1
Acties:
  • 192 views sinds 30-01-2008
  • Reageer

  • knopper
  • Registratie: September 2001
  • Laatst online: 25-12-2025

knopper

Sander Knopper

Topicstarter
Hoi allemaal,

Ben bezig met een simpel programmaatje en wilde mijzelf graag de GridBagLayout eigen maken. Nu zit ik alleen met een (noob) probleem, ik het de volgende code:

Java:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class inputDive {

        public static void main (String args[]) {

        JFrame mainScreen = new JFrame ("inputDive");

        Container content = mainScreen.getContentPane ();
        content.setLayout (new GridBagLayout ());

        GridBagConstraints constraints = new GridBagConstraints ();

        JLabel name = new JLabel ("Your name");
        constraints.gridx = 0;
        constraints.gridy = 0;
        constraints.ipady = 2;
        constraints.ipadx = 2;
        content.add (name, constraints);

        JTextField namefield = new JTextField (20);
        constraints.gridx = 1;
        constraints.gridy = 0;
        constraints.ipady = 2;
        constraints.ipadx = 2;
        content.add (namefield, constraints);

        JLabel email = new JLabel ("Email address");
        constraints.gridx = 0;
        constraints.gridy = 1;
        constraints.ipady = 2;
        constraints.ipadx = 2;
        content.add (email, constraints);

        mainScreen.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
        mainScreen.setSize (640, 480);
        mainScreen.setVisible (true);
        }
}


Het probleem is dat de text (en het textfield natuurlijk) in het midden van de hun toegewezen ruimte gaan zitten terwijl ik ze graag links uitgelijnd wil hebben. Kan iemand me vertellen hoe dit het makkelijkste gaat?

  • Robtimus
  • Registratie: November 2002
  • Laatst online: 20:53

Robtimus

me Robtimus no like you

constraints.anchor?
This field is used when the component is smaller than its display area. It determines where, within the display area, to place the component.

More than meets the eye
There is no I in TEAM... but there is ME
system specs