JSeparator und Layoutproblem in Kombo mit JPanel und JTextFi

Status
Nicht offen für weitere Antworten.

Buschel

Mitglied
Hallo, ich möchte gerne ein Layout schaffen, dass ungefähr so aussehen soll:

__|Label|___________________________
..................................| Label | TextField|
..................................| Label | TextField|
..................................| Label | TextField|
__|Label|___________________________
..................................| Label | TextField|
..................................| Label | TextField|
..................................| Label | TextField|


Das TextField und das Label sollen rechtsbündig sein und ganz oben im JFrame soll ein Separator stehen in dem
ein Label eingebunden ist. Das ganze dann 2mal.

Ich habe schon versucht das mit dem Springlayout hinzubekommen, doch dabei zerschießt mir dieses
Layout meine MaximaleSize vom TextField und das sieht dann nachher so aus:

|Label|TextField TextField TextField TextField |

(Sprich das TextField fängt zwar rechtsbündig an, schiebt jedoch das Label ganz nach Links und beansprucht den Restplatz)


Zu dem wird mein JSeparator nicht angezeigt.

Gibt es eine bessere Implementierung für dieses Problem?

Würde mich über ein Lösung für dieses Problem sehr freuen. :D
 

André Uhres

Top Contributor
Code:
//package layout;
/*
 * Layout2.java
 */
import java.awt.*;
import javax.swing.*;
public class Layout2 extends JFrame {
    public Layout2() {
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        mainPanel = new JPanel();
        mainPanel.setLayout(new GridLayout(2, 1));
        Group group1 = new Group();
        Group group2 = new Group();
        mainPanel.add(group1);
        mainPanel.add(group2);
        getContentPane().add(mainPanel, BorderLayout.CENTER);
        pack();
    }
    public static void main(String args[]) {new Layout2().setVisible(true);}
    private JPanel mainPanel;
    private Group group1, group2;
    class Group extends JPanel{
        public Group(){
            separator = new Separator();
            inputPanel = new JPanel();
            jLabel1 = new JLabel("Label1");
            jTextField1 = new JTextField();
            jLabel2 = new JLabel("Label2");
            jTextField2 = new JTextField();
            jLabel3 = new JLabel("Label3");
            jTextField3 = new JTextField();
            setLayout(new BorderLayout());
            add(separator, BorderLayout.NORTH);
            inputPanel.setPreferredSize(new Dimension(200, 100));
            jLabel1.setPreferredSize(new Dimension(80, 14));
            inputPanel.add(jLabel1);
            jTextField1.setPreferredSize(new Dimension(110, 19));
            inputPanel.add(jTextField1);
            jLabel2.setPreferredSize(new Dimension(80, 14));
            inputPanel.add(jLabel2);
            jTextField2.setPreferredSize(new Dimension(110, 19));
            inputPanel.add(jTextField2);
            jLabel3.setPreferredSize(new Dimension(80, 14));
            inputPanel.add(jLabel3);
            jTextField3.setPreferredSize(new Dimension(110, 19));
            inputPanel.add(jTextField3);
            add(inputPanel, BorderLayout.EAST);
        }
        private Separator separator;
        private JPanel inputPanel;
        private JLabel jLabel1, jLabel2, jLabel3;
        private JTextField jTextField1, jTextField2, jTextField3;
    }
    class Separator extends JPanel{
        public Separator(){
            setPreferredSize(new Dimension(400, 20));
            sep1 = new JSeparator();
            sep2 = new JSeparator();
            sepLabel = new JLabel("Seperator");
            sepLabel.setPreferredSize(new Dimension(55, 20));
            setLayout(new GridBagLayout());
            GridBagConstraints gridBagConstraints;
            gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
            gridBagConstraints.anchor = GridBagConstraints.WEST;
            gridBagConstraints.weightx = 3.0;
            add(sep1, gridBagConstraints);
            gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.gridx = 1;
            gridBagConstraints.weightx = 0.5;
            gridBagConstraints.insets = new Insets(0, 0, 2, 0);
            add(sepLabel, gridBagConstraints);
            gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.gridx = 2;
            gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
            gridBagConstraints.anchor = GridBagConstraints.EAST;
            gridBagConstraints.weightx = 10.0;
            add(sep2, gridBagConstraints);
        }
        private JSeparator sep1, sep2;
        private JLabel sepLabel;
    }
}
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
G Layoutproblem Java Basics - Anfänger-Themen 4
M LayoutProblem Java Basics - Anfänger-Themen 8

Ähnliche Java Themen

Neue Themen


Oben