LayoutManager LayoutManager gesucht

  • Themenstarter Themenstarter Gast2
  • Beginndatum Beginndatum
G

Gast2

Gast
Moin,

entstehen soll das Layout im Anhang ... links oben komplett fest, rechts unten komplett flexibel (je nach Fenstergröße) ... die anderen beiden entsprechend angepasst

ich habe es erst mit JSplitPane probiert

Java:
public class SplitPaneDemo extends JFrame {

	private static final long serialVersionUID = 1L;

	public SplitPaneDemo() {
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		setBounds(0, 0, 1280, 800);
		System.out.println(getLayout().getClass().getName());
		
		root = new JSplitPane();
		root.setDividerLocation(250);
		root.setDividerSize(0);
		this.add(root);
		
		left = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
		left.setDividerLocation(250);
//		left.setBounds(0, 0, 250, 400);
//		left.setBounds(0, 0, 250, 4000);
//		left.setDividerSize(0);
		
		root.setLeftComponent(left);
		
		setVisible(true);
	}
	
	JSplitPane root;
	JSplitPane left;
	JSplitPane right;
}

ich erreiche maximal die Rechts/Links Teilung ... sowie ich den Rechten oder Linken nochmal teilen will, erhalte ich Nichts

also habe ich mich an GridBagLayout versucht

Java:
public class GBDemo extends JFrame {

	private static final long serialVersionUID = 1L;

	public static void main(String args[]) {
//		new GBDemo();
		new SplitPaneDemo();
	}
	
	private GridBagLayout gridbag = new GridBagLayout();
	
	private GBDemo() {
		setLayout(gridbag);
		setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
		setBounds(0, 0, 1280, 800);
		
		JButton view = new JButton( "QuickView" );
		view.setPreferredSize(new Dimension(250, 250));
		GridBagConstraints viewconst = new GridBagConstraints();
		viewconst.gridx = 0;
		viewconst.gridy = 0;
		viewconst.weightx = 0.0;
		viewconst.weighty = 0.0;
		viewconst.gridwidth = 1;
		viewconst.gridheight = 1;
		viewconst.anchor = GridBagConstraints.NORTHWEST;
		
		JButton messages = new JButton( "Meldungen" );
		messages.setPreferredSize(new Dimension(250, 250));
		GridBagConstraints msgconst = new GridBagConstraints();
		msgconst.gridx = 1;
		msgconst.gridy = 0;
		msgconst.weightx = 1.0;
		msgconst.weighty = 1.0;
		msgconst.gridwidth = 1;
		msgconst.gridheight = 1;
		msgconst.fill = GridBagConstraints.BOTH;
		
		JButton list = new JButton( "Regions" );
		GridBagConstraints listconst = new GridBagConstraints();
		listconst.gridx = 0;
		listconst.gridy = 1;
		listconst.weightx = 1.0;
		listconst.weighty = 1.0;
		listconst.gridwidth = 1;
		listconst.gridheight = 1;
		listconst.fill = GridBagConstraints.BOTH;
		
		JButton map = new JButton( "Map" );
		GridBagConstraints mapconst = new GridBagConstraints();
		mapconst.gridx = 1;
		mapconst.gridy = 1;
		mapconst.weightx = 1.0;
		mapconst.weighty = 1.0;
		mapconst.gridwidth = 1;
		mapconst.gridheight = 1;
		mapconst.fill = GridBagConstraints.BOTH;
		
		add( view, viewconst );
		add( messages, msgconst );
		add( list, listconst );
		add( map, mapconst );
		
		setVisible(true);
	}
}

damit komme ich auch nicht wirklich weiter ... ich kann zwar oben-links in der maximalen Breite festlegen ... aber mehr auch nicht -.-

im Moment reagiere ich bei einer Festgröße und passe manuelle die 4 (bzw. 3) Flächen manuell an

hand, mogel
 

Anhänge

  • WunschLayout.jpeg
    WunschLayout.jpeg
    9,6 KB · Aufrufe: 41
Meine Empfehlung: GroupLayout:
Java:
public class LayoutTest extends JFrame {

	private JPanel contentPane;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					LayoutTest frame = new LayoutTest();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public LayoutTest() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 450, 300);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		
		JPanel panel1 = new JPanel();
		panel1.setPreferredSize(new Dimension(50,50));
		panel1.setBorder(new LineBorder(new Color(0, 0, 0)));
		
		JPanel panel2 = new JPanel();
		panel2.setBorder(new LineBorder(Color.RED));
		
		JPanel panel3 = new JPanel();
		panel3.setBorder(new LineBorder(Color.GREEN));
		
		JPanel panel4 = new JPanel();
		panel4.setBorder(new LineBorder(Color.BLUE));
		GroupLayout layout = new GroupLayout(contentPane);
		layout.setAutoCreateContainerGaps(true);
		
		layout.setHorizontalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addComponent(panel1)
						.addComponent(panel3))
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addComponent(panel4)
						.addComponent(panel2))
				)
		);
		layout.setVerticalGroup(
			layout.createParallelGroup(Alignment.LEADING)
				.addGroup(layout.createSequentialGroup()
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addComponent(panel2)
						.addComponent(panel1))
					.addGroup(layout.createParallelGroup(Alignment.LEADING)
						.addComponent(panel3)
						.addComponent(panel4))
				)
		);
		layout.linkSize(SwingConstants.HORIZONTAL,panel1,panel3);
		layout.linkSize(SwingConstants.VERTICAL,panel1,panel2);
		
		contentPane.setLayout(layout);
	}
}
 
falls noch jemand darüber stolpern sollte ... es könnte von Vorteil sein jedem "Objekt" eine passende "prefered" Größe anzuhängen ... die JTabbedPane ist per Default größer als ich sie benötigte ... dadurch war Oben-Links nix mehr Quadratisch ... nachdem ich die JTabbedPane ebenfalls mit 250x250 bevorzuge, funktionierte es auch wie im Beispiel
 

Neue Themen


Zurück
Oben