GridBagLayout in GridBagLayout

richiking

Mitglied
Hallo,

ich habe ein komplexeres GUI zu erstellen und hab gehört mit dem GRidBagLayout lässt sich das schön realisieren.

Leider scheitere ich gerade daran ein Panel mit einem GridBagLayout in ein anderes Panel mit GridBaglayout einzufügen.

Funktion zum hinzufügen von Components

Java:
static void addComponent(Container cont, GridBagLayout gbl, Component c, int x, int y, int width, int height, double weightx, double weighty,
			int ipadx, int ipady, int anchor)
	{
		GridBagConstraints gbc = new GridBagConstraints();
		gbc.gridx = x; gbc.gridy = y;
		gbc.gridwidth = width; gbc.gridheight = height;
		gbc.weightx = weightx; gbc.weighty = weighty;
		gbc.ipadx = ipadx;
		gbc.ipady = ipady;
		gbc.anchor = anchor;
		gbc.insets = new Insets(5,20,10,20);
		gbl.setConstraints( c, gbc );	    
		cont.add( c );
}


"Mutterpanel"

Java:
Container contain = this.getContentPane();
		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
		GridBagLayout gbl = new GridBagLayout();
		contain.setLayout(gbl);

addComponent(contain, gbl, lbl_title,0,0,6,1,1.0,1.0,0,0,GridBagConstraints.CENTER); 		
		
addComponent(contain, gbl, p_control, 0,1,6,1,1.0,1.0,0,0,GridBagConstraints.CENTER);


Buttons-Panel

Java:
JPanel p_control = new JPanel();
		p_control.setLayout(new GridBagLayout());
		
		addComponent(p_control,    gbl1,    btt_connect,      	0,      0,      1,      1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    btt_start,   		1,   	0,   	1,   	1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    btt_stop,   		2,   	0,   	1,   	1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    btt_getclock,   	3,   	0,   	1,   	1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    btt_setconfig,   	4,   	0,   	1,   	1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    btt_savedata,   	5,   	0,   	1,   	1,   1.0,   1.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    list_ports,   		0,   	1,   	1,   	1,   1.0,   2.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    box_uart,   		1,   	1,   	1,   	1,   1.0,   2.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    box_sdcard,   		2,   	1,   	1,   	1,   1.0,   2.0,   0,   0,   GridBagConstraints.CENTER);
		addComponent(p_control,    gbl1,    box_mode,   		3,   	1,   	1,   	1,   1.0,   2.0,   0,   0,   GridBagConstraints.CENTER);


So sieht das dann aus:

Anhang anzeigen 4097


Ich hätte die RadioButtons aber gerne direkt unter den Buttons... Nach meinem logischen Empfinden hätte ich das richtig eingestellt... aber es will halt nicht...

lg, richi
 
Falls nötig hier noch die Konfiguration der Boxen für die RadioButtons

Java:
Box box_uart = Box.createVerticalBox();
				box_uart.setBorder(BorderFactory.createTitledBorder("UART Transmission"));
				ButtonGroup bttg_uart = new ButtonGroup();
				bttg_uart.add(rbtt_uart);
				bttg_uart.add(rbtt_uart1);
				box_uart.add(rbtt_uart);
				box_uart.add(rbtt_uart1);
				
				Box box_sdcard = Box.createVerticalBox();
				box_sdcard.setBorder(BorderFactory.createTitledBorder("SD CARD"));
				ButtonGroup bttg_sdcard = new ButtonGroup();
				bttg_sdcard.add(rbtt_sd);
				bttg_sdcard.add(rbtt_sd1);
				box_sdcard.add(rbtt_sd);
				box_sdcard.add(rbtt_sd1);
					
				Box box_mode = Box.createVerticalBox();
				box_mode.setBorder(BorderFactory.createTitledBorder("Mode"));
				ButtonGroup bttg_mode = new ButtonGroup();
				bttg_mode.add(rbtt_mode);
				bttg_mode.add(rbtt_mode1);
				box_mode.add(rbtt_mode);
				box_mode.add(rbtt_mode1);
 

Zurück
Oben