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
"Mutterpanel"
Buttons-Panel
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
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