JLabel, JSeparator kombinieren?

flashray

Erfahrenes Mitglied
Hallo Freunde,

ich möchte statt einem TitledBorder ein JLabel kombiniert mit einem JSeparator verwenden. Allerdings habe ich es leider nicht geschafft, ein JSeparator neben einem JLabel vertikal zentriert anzuordnen.

Java:
import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.*;

public class SeparatorProblem extends JFrame {

	private JPanel p = new JPanel();
	private JLabel l = new JLabel("Überschrift: ");
	private JSeparator s = new JSeparator(JSeparator.HORIZONTAL);
	
	private JTextArea t = new JTextArea();
	
	public SeparatorProblem() {
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationByPlatform(true);
		
		t.setPreferredSize(new Dimension(300,300));

		p.setLayout(new BorderLayout());
		p.add(l,BorderLayout.WEST);
		p.add(s,BorderLayout.CENTER);
		
		this.add(p,BorderLayout.NORTH);
		this.add(t,BorderLayout.CENTER);		
		this.pack();
		
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new SeparatorProblem();
	}
}


Vg Erdal
 
Habs doch noch hinbekommen.

Java:
import java.awt.*;

import javax.swing.*;

public class SeparatorProblem extends JFrame {

	private JPanel p = new JPanel();
	private JLabel l = new JLabel("Überschrift: ");
	private JSeparator s = new JSeparator(JSeparator.HORIZONTAL);
	
	private JTextArea t = new JTextArea();
	
	public SeparatorProblem() {
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setLocationByPlatform(true);

		t.setPreferredSize(new Dimension(300,300));

		p.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		p.add(l,c);
		c.fill = GridBagConstraints.HORIZONTAL;
		c.weightx = 1;
		c.gridx = 1;
		p.add(s,c);
		
		this.add(p,BorderLayout.NORTH);
		this.add(t,BorderLayout.CENTER);
		this.pack();
		
		this.setVisible(true);
	}

	public static void main(String[] args) {
		new SeparatorProblem();
	}
}

Vg Erdal
 
Zurück