Wie Layout mit welchen Swing Managern umsetzen?

Status
Nicht offen für weitere Antworten.
W

Waynes

Gast
Hallöle,

wie sprich mit welchen Layout Managern würdet ihr folgendes Layout umsetzen?

avdfx6volf3ie81gp.jpg
 
W

Waynes

Gast
Kennst du eine deutsche website die das GridbagLayout erklärt
 
W

Waynes

Gast
was ist denn einfacher zu lernen gridbaglayout oder tablelayout, da du ja sagst es geht beides?
 
W

Waynes

Gast
gibt es eigentlich unterschiede in der Ausführungsgeschwindigkeit von den verschiedenen layoutmanagern?

Ich sah gerade, dass ich den table layout manager gar nicht für mein template benutzen könnte, da der table layout manager ja nur gerade zeilen,spalten macht mit objekten sprich wie eine tabelle eben. Die letzten 5 blauen rechtecke würden damit ja gar nicht gehen.

Ist es normal, dass man für ein fenster mit steeuerelementen 3 verschiedene manager benutzt oder zeugt das von Unkenntnis?
 

L-ectron-X

Gesperrter Benutzer
TableLayout kann jedes beliebige Layout abdecken, also auch deins.
Natürlich kannst du auch Panels mit LayoutManagern verschachteln.
 
W

Waynes

Gast
L-ectron-X hat gesagt.:
TableLayout kann jedes beliebige Layout abdecken, also auch deins.
Natürlich kannst du auch Panels mit LayoutManagern verschachteln.

das GridBagLayout ist ja ne AWT klasse kann ich dann damit swing komponenten benutzen? soll man ja nicht mischen...
 

L-ectron-X

Gesperrter Benutzer
Du solltest nur auf die Mischung von Objekten verzichten, die von Component bzw. JComponent erben.
LayoutManager und viele andere AWT-Klassen sind davon logischerweise nicht betroffen.
 
W

Waynes

Gast
L-ectron-X hat gesagt.:
Du solltest nur auf die Mischung von Objekten verzichten, die von Component bzw. JComponent erben.
LayoutManager und viele andere AWT-Klassen sind davon logischerweise nicht betroffen.

ok super...

kannst du mir sagen warum die 2 JTextFields nicht ganz oben am fenster anfangen?? warum so weit unten?

avdu4he1gtd4urecp.gif


das ist der code:

Code:
public class MainWindow extends JFrame
{

	
	
	public MainWindow()
	{		
		GridBagConstraints constraints = new GridBagConstraints();
	    setLayout(new GridBagLayout());		 
	    Component c;	
 
		    
            //---------------------------------------------------
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    constraints.fill = GridBagConstraints.HORIZONTAL;
		    constraints.insets = new Insets(0, 1, 0, 1);
		    c = new JTextField("test");
		    defineFont(c);
		    add(c, constraints);
		    
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    constraints.fill = GridBagConstraints.HORIZONTAL;		    
		    constraints.insets = new Insets(0, 1, 0, 1);
		    c = new JTextField("test");
		    defineFont(c);
		    add(c, constraints);
		    //---------------------------------------------------
		    
		    constraints.weightx = 1.0;
		    constraints.gridwidth = GridBagConstraints.RELATIVE;
		    c = new JLabel("Sorte:");
		    defineFont(c);
		    add(c, constraints);
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    c = new JLabel("Extras:");
		    defineFont(c);
		    add(c, constraints);

		    constraints.fill = GridBagConstraints.NONE; 
		    constraints.gridwidth = GridBagConstraints.RELATIVE;
		    c = new JCheckBox("Margherita");
		    defineFont(c);
		    add(c, constraints);
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    c = new JCheckBox("Mais");
		    defineFont(c);
		    add(c, constraints);
		    c = new JCheckBox("Schinken");
		    defineFont(c);
		    constraints.gridwidth = GridBagConstraints.RELATIVE;
		    add(c, constraints);
		    c = new JCheckBox("Pfeffersalami");
		    defineFont(c);
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    add(c, constraints);

		    c = new JLabel("Anmerkungen:");
		    defineFont(c);
		    add(c, constraints);

		    constraints.fill = GridBagConstraints.BOTH; 
		    constraints.gridwidth = 1;
		    constraints.gridheight = 2;
		    constraints.insets = new Insets(0, 5, 0, 5);
		   
		    c = new JTextField();
		    defineFont(c);
		    add(c, constraints);
		   
		    constraints.anchor = GridBagConstraints.WEST;
		    constraints.fill = GridBagConstraints.NONE; 
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    constraints.gridheight = 1;
		    
		    c = new JCheckBox("Abholer");
		    
		    defineFont(c);
		    add(c, constraints);
		    c = new JButton("Löschen");
		    defineFont(c);
		    add(c, constraints);
		 
		    constraints.anchor = GridBagConstraints.CENTER;
		    constraints.fill = GridBagConstraints.NONE;
		    constraints.gridwidth = GridBagConstraints.RELATIVE;
		    constraints.insets = new Insets(20, 0, 0, 0);
		    c = new JButton("OK");
		    defineFont(c);
		    add(c, constraints);
		    constraints.gridwidth = GridBagConstraints.REMAINDER;
		    c = new JButton("Abbruch");
		    defineFont(c);
		    add(c, constraints);
		    //pack();
		
		
		
		
	}
	
	 void defineFont(Component c) {
		    c.setFont(new Font("SansSerif", Font.PLAIN, 12));
		  }

	
	public static void main(String[] args)
	{
		
		  JFrame.setDefaultLookAndFeelDecorated(true); 
		MainWindow fenster = new MainWindow();
		fenster.setSize(300,500);
		fenster.setResizable(false);
		fenster.setVisible(true);
		

		
	}

}
 
W

Waynes

Gast
liegt das villeicht daran, dass je mehr elemente ich hinzufüge, desto mehr das ganze dann nach oben rutscht?
 
W

Waynes

Gast
Kann mir jemand sagen, warum die beiden buttons 19 und 20 sich überlagern und nicht mittig nebeneinander liegen?

avdwx1y8ytr7u3rvl.gif
 
W

Waynes

Gast
geschafft doch irgendwie ist das GridBagLayout ziemlich unbrauchbar oder ich kenne nicht die volle Power....

wie schaffe ich es, die letzten 3 buttons so zu verteilen dass Sie die Breite voll einnehmen und alle 3 buttons gleichmäßig breit sind? sprich width= 33 % jeder button ?

avdy13p9xv2bgxp7l.gif
 

L-ectron-X

Gesperrter Benutzer
Naja, du hast vier Zellen eingerichtet. Das lässt sich auf 3 Buttons schlecht aufteilen. Es wird immer Verschiebungen geben bei Größenänderung des Fensters.
Lege die drei Buttons einfach in ein weiteres Panel mit GridLayout. Das Panel packst du dann in die untere Zelle auf voller Breite.
 
W

Waynes

Gast
L-ectron-X hat gesagt.:
Naja, du hast vier Zellen eingerichtet. Das lässt sich auf 3 Buttons schlecht aufteilen. Es wird immer Verschiebungen geben bei Größenänderung des Fensters.
Lege die drei Buttons einfach in ein weiteres Panel mit GridLayout. Das Panel packst du dann in die untere Zelle auf volle Breite.
ok danke ich probiers, doch erwähnte ich , dass das Fenster nicht resized werden kann ist auf setResizeable(false) gesetzt.
 
W

Waynes

Gast
woran siehst du dass ich 4 Zellen eingerichtet habe? weil die größte Anzahl der Zellen bzw. buttons 4 je zeile ist?
 
W

Waynes

Gast
oh man also ich werde aus dem GBL Manager nicht schlau, gibt denn nicht eine gute Site die jeden Parameter im detail erklälrt mit abbildung? DPunkt.de und das sun java tutorial kann man voll vergessen... vor allem auf english nicht mein fall :-(
 
W

Waynes

Gast
also das ist mein Code bzw. der wurde teilweise irgendwo aus dem internet gerippt... Ich habe keine ahnung, wie ich in diese dämliche Konstrukt einen 2. GBL Manager bekomme ohne eine Fehlermeldung.

Ich muss sagen, dafür dass eine Oma meine Anwendung etwas anders sieht wenn sie einen Mac benutzt anstatt windows pc wenn sie das fenster resized oder die schrift ihr zu klein ist weil man das Fenster nicht resizen kann ist mir so langsam schnuppe, schau dir doch mal den chaotischen Code an wer blickt da noch durch im Vergleich zum Null Layout ist das ja Hölle :roll:
Code:
public class GridBagLayoutDemo {
    final static boolean shouldFill = true;
    final static boolean shouldWeightX = true;
    final static boolean RIGHT_TO_LEFT = false;

    public static void addComponentsToPane(Container pane)
    {
    	
    	
    JButton button;
	pane.setLayout(new GridBagLayout());		
	
	GridBagConstraints c = new GridBagConstraints();
	
	c.fill = GridBagConstraints.HORIZONTAL;
	c.gridwidth = GridBagConstraints.REMAINDER;
	c.insets = new Insets(1, 1, 1, 1);	
	
	button = new JButton("Button 1");	 
	c.weightx = 0.5;		
	c.gridx = 0;
	c.gridy = 0;
	pane.add(button, c);
	

	button = new JButton("Button 2");	
	c.weightx = 0.5;
	c.gridx = 0;
	c.gridy = 1;
	pane.add(button, c);
	
	//-------------------------------------------------------------------------------------------------//
    c.gridwidth = 1;
	button = new JButton("Button 3");		
	c.gridx = 0;
	c.gridy = 2;
	pane.add(button, c);
	
     
	button = new JButton("Button 4");	
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 2;
	c.gridy = 2;
	pane.add(button, c);
	
	button = new JButton("Button 5");	
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 3;
	c.gridy = 2;
	pane.add(button, c);
	
	button = new JButton("Button 6");	
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 4;
	c.gridy = 2;
	pane.add(button, c);	
	
	/*----------------------------------------------------------------------------------------------------*/
	
	button = new JButton("Button 7");
	c.ipadx = 20;		
	c.gridx = 0;
	c.gridy = 3;
	pane.add(button, c);		
     
	button = new JButton("Button 8");				
	c.ipadx = 80;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 2;
	c.gridy = 3;
	pane.add(button, c);
	
	button = new JButton("Button 9");	
	c.ipadx = 80;       // mach horizontalen vergrößerung des elements in x-richtung sprich breiter
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 3;
	c.gridy = 3;
	pane.add(button, c);
	
	button = new JButton("Button 10");	
	c.ipadx = 20;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 4;
	c.gridy = 3;
	pane.add(button, c);
	
	/*----------------------------------------------------------------------------------------------------*/
	
	button = new JButton("Button 11");
	c.ipadx = 20;		
	c.gridx = 0;
	c.gridy = 4;
	pane.add(button, c);		
     
	button = new JButton("Button 12");				
	c.ipadx = 80;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 2;
	c.gridy = 4;
	pane.add(button, c);
	
	button = new JButton("Button 13");	
	c.ipadx = 80;       // mach horizontalen vergrößerung des elements in x-richtung sprich breiter
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 3;
	c.gridy = 4;
	pane.add(button, c);
	
	button = new JButton("Button 14");	
	c.ipadx = 20;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 4;
	c.gridy = 4;
	pane.add(button, c);
	
	/*----------------------------------------------------------------------------------------------------*/
		
	button = new JButton("Button 15");
	c.ipadx = 20;		
	c.gridx = 0;
	c.gridy = 5;
	pane.add(button, c);		
     
	button = new JButton("Button 16");				
	c.ipadx = 80;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 2;
	c.gridy = 5;
	pane.add(button, c);
	
	button = new JButton("Button 17");	
	c.ipadx = 80;       // mach horizontalen vergrößerung des elements in x-richtung sprich breiter
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 3;
	c.gridy = 5;
	pane.add(button, c);
	
	button = new JButton("Button 18");	
	c.ipadx = 20;
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 4;
	c.gridy = 5;
	pane.add(button, c);
	
	//---------------------------------------------------------------------------------------------------
	 
		
	c.gridwidth = 3; 
	button = new JButton("Button xx");
	c.fill = GridBagConstraints.HORIZONTAL;
	c.gridx = 0;
	c.gridy = 6;
	pane.add(button, c);

 
	button = new JButton("Button dd");
	c.fill = GridBagConstraints.HORIZONTAL;
	c.gridx = 3;
	c.gridy = 6;
	pane.add(button, c);
	
	/*----------------------------------------------------------------------------------------------------*/
	
	c.gridwidth = GridBagConstraints.REMAINDER;
	button = new JButton("Button fott");	
	c.ipady = 85;
	c.weightx = 0.5;		
	c.gridx = 0;
	c.gridy = 7;
	pane.add(button, c);
	
	
	button = new JButton("Button foobar");	
	
	c.weightx = 0.5;
	c.gridx = 0;
	c.gridy = 8;
	pane.add(button, c);
	
	/*-----------------------------------------------------------------------------------------------------*/
	
	c.ipady = 5;
	c.gridwidth = 4;
	button = new JButton("Button dead");
	c.gridx = 0;
	c.gridy = 9;
	pane.add(button, c);

	
	button = new JButton("Button hello");
	c.gridx = 4;
	c.gridy = 9;
	pane.add(button, c);
	
	/*-----------------------------------------------------------------------------------------------------*/
	
	
	
	c.gridwidth = 1;
	button = new JButton("Button 3");		
	c.gridx = 0;
	c.gridy = 10;
	pane.add(button, c);
	
     
	button = new JButton("Button 4");	
	c.weightx = 0.5;	//sorgot dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 2;
	c.gridy = 10;
	pane.add(button, c);
	
	button = new JButton("Button 5");	
	c.weightx = 0.5;	//sorgt dafür das nebeneinanderliegende elemente gleich groß sind
	c.gridx = 3;
	c.gridy = 10;
	pane.add(button, c);
	
	 
    
	
	
    }

    /**
     * Create the GUI and show it.  For thread safety,
     * this method should be invoked from the
     * event-dispatching thread.
     */
    private static void createAndShowGUI() {
        //Create and set up the window.
        JFrame frame = new JFrame("GridBagLayoutDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

        //Set up the content pane.
        addComponentsToPane(frame.getContentPane());

        //Display the window.
        frame.pack();
        frame.setSize(382,520);
        frame.setResizable(false);
        frame.setVisible(true);
    }

    public static void main(String[] args)
    {
        
        javax.swing.SwingUtilities.invokeLater(new Runnable()
        {
            public void run() {
                createAndShowGUI();
            }
        });
    }
}
 

L-ectron-X

Gesperrter Benutzer
LayoutDemo.gif


Sieht dann so aus:
Code:
import java.awt.*;
import javax.swing.*;

public class GridbagLayoutDemo extends JFrame {
   private JButton jButton1;
   private JButton jButton10;
   private JButton jButton11;
   private JButton jButton12;
   private JButton jButton13;
   private JButton jButton14;
   private JButton jButton15;
   private JButton jButton16;
   private JButton jButton17;
   private JButton jButton18;
   private JButton jButton19;
   private JButton jButton2;
   private JButton jButton20;
   private JButton jButton21;
   private JButton jButton22;
   private JButton jButton23;
   private JButton jButton24;
   private JButton jButton25;
   private JButton jButton26;
   private JButton jButton27;
   private JButton jButton3;
   private JButton jButton4;
   private JButton jButton5;
   private JButton jButton6;
   private JButton jButton7;
   private JButton jButton8;
   private JButton jButton9;
   private JPanel panel;

   public GridbagLayoutDemo(String title) {
      super(title);
      setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
      setSize(380, 520);
      setLocationRelativeTo(null);

      GridBagConstraints constraints;

      getContentPane().setLayout(new GridBagLayout());

      jButton1 = new JButton("Button 1");
      constraints = new GridBagConstraints();
      constraints.gridwidth = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(2, 2, 1, 2);
      getContentPane().add(jButton1, constraints);

      jButton2 = new JButton("Button 2");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 1;
      constraints.gridwidth = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 2);
      getContentPane().add(jButton2, constraints);

      jButton3 = new JButton("Button 3");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      constraints.weightx = 0.25;
      getContentPane().add(jButton3, constraints);

      jButton4 = new JButton("Button 4");
      constraints = new GridBagConstraints();
      constraints.gridx = 1;
      constraints.gridy = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      constraints.weightx = 0.25;
      getContentPane().add(jButton4, constraints);

      jButton5 = new JButton("Button 5");
      constraints = new GridBagConstraints();
      constraints.gridx = 2;
      constraints.gridy = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      constraints.weightx = 0.25;
      getContentPane().add(jButton5, constraints);

      jButton6 = new JButton("Button 6");
      constraints = new GridBagConstraints();
      constraints.gridx = 3;
      constraints.gridy = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      constraints.weightx = 0.25;
      getContentPane().add(jButton6, constraints);

      jButton7 = new JButton("Button 7");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 3;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      getContentPane().add(jButton7, constraints);

      jButton8 = new JButton("Button 8");
      constraints = new GridBagConstraints();
      constraints.gridx = 1;
      constraints.gridy = 3;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton8, constraints);

      jButton9 = new JButton("Button 9");
      constraints = new GridBagConstraints();
      constraints.gridx = 2;
      constraints.gridy = 3;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton9, constraints);

      jButton10 = new JButton("Button 10");
      constraints = new GridBagConstraints();
      constraints.gridx = 3;
      constraints.gridy = 3;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      getContentPane().add(jButton10, constraints);

      jButton11 = new JButton("Button 11");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      getContentPane().add(jButton11, constraints);

      jButton12 = new JButton("Button 12");
      constraints = new GridBagConstraints();
      constraints.gridx = 1;
      constraints.gridy = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton12, constraints);

      jButton13 = new JButton("Button 13");
      constraints = new GridBagConstraints();
      constraints.gridx = 2;
      constraints.gridy = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton13, constraints);

      jButton14 = new JButton("Button 14");
      constraints = new GridBagConstraints();
      constraints.gridx = 3;
      constraints.gridy = 4;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      getContentPane().add(jButton14, constraints);

      jButton15 = new JButton("Button 15");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 5;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      getContentPane().add(jButton15, constraints);

      jButton16 = new JButton("Button 16");
      constraints = new GridBagConstraints();
      constraints.gridx = 1;
      constraints.gridy = 5;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton16, constraints);

      jButton17 = new JButton("Button 17");
      constraints = new GridBagConstraints();
      constraints.gridx = 2;
      constraints.gridy = 5;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 1);
      getContentPane().add(jButton17, constraints);

      jButton18 = new JButton("Button 18");
      constraints = new GridBagConstraints();
      constraints.gridx = 3;
      constraints.gridy = 5;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      getContentPane().add(jButton18, constraints);

      jButton19 = new JButton("Button 19");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 6;
      constraints.gridwidth = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      getContentPane().add(jButton19, constraints);

      jButton20 = new JButton("Button 20");
      constraints = new GridBagConstraints();
      constraints.gridx = 2;
      constraints.gridy = 6;
      constraints.gridwidth = 2;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      getContentPane().add(jButton20, constraints);

      jButton21 = new JButton("Button 21");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 7;
      constraints.gridwidth = 4;
      constraints.gridheight = 2;
      constraints.fill = GridBagConstraints.BOTH;
      constraints.insets = new Insets(1, 2, 1, 2);
      constraints.weightx = 1.0;
      constraints.weighty = 0.5;
      getContentPane().add(jButton21, constraints);

      jButton22 = new JButton("Button 22");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 9;
      constraints.gridwidth = 4;
      constraints.gridheight = 2;
      constraints.fill = GridBagConstraints.BOTH;
      constraints.insets = new Insets(1, 2, 1, 2);
      constraints.weightx = 1.0;
      constraints.weighty = 0.5;
      getContentPane().add(jButton22, constraints);

      jButton23 = new JButton("Button 23");
      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 11;
      constraints.gridwidth = 3;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 2, 1, 1);
      constraints.weightx = 1.0;
      getContentPane().add(jButton23, constraints);

      jButton24 = new JButton("Button 24");
      constraints = new GridBagConstraints();
      constraints.gridx = 3;
      constraints.gridy = 11;
      constraints.fill = GridBagConstraints.HORIZONTAL;
      constraints.insets = new Insets(1, 1, 1, 2);
      getContentPane().add(jButton24, constraints);

      panel = new JPanel(new GridLayout(1, 0, 2, 0));
      jButton25 = new JButton("Button 25");
      jButton26 = new JButton("Button 26");
      jButton27 = new JButton("Button 27");
      panel.add(jButton25);
      panel.add(jButton26);
      panel.add(jButton27);

      constraints = new GridBagConstraints();
      constraints.gridx = 0;
      constraints.gridy = 12;
      constraints.gridwidth = 4;
      constraints.fill = GridBagConstraints.BOTH;
      constraints.insets = new Insets(1, 2, 2, 1);
      getContentPane().add(panel, constraints);
   }

   public static void main(String args[]) {
      new GridbagLayoutDemo("GridbagLayoutDemo").setVisible(true);
   }
}
 
W

Waynes

Gast
super das ist doch mal was!!! doch eine schwierige Frage hätte ich noch... wie bekomme ich BUTTON 24 auf 1/3 seiner Größe gleichzeit sollen sich die 2/3 weggefallene Breite den BUTTON 23 verbreitern?

das Problem daran so beschleibt mich ein Gefühl ist... dies geht entweder nicht, oder man muss das komplette layout ändern richtig?
Kannst du es mir zeigen oder sagen was man machen müsste?
Ich will doch von dem n00b-null layout weg auch wenn es sehr geschickt ist ;P
 

L-ectron-X

Gesperrter Benutzer
Waynes hat gesagt.:
wie bekomme ich BUTTON 24 auf 1/3 seiner Größe gleichzeit sollen sich die 2/3 weggefallene Breite den BUTTON 23 verbreitern?
Das geht nur noch, wenn du mehr horizontale Zellen für die Buttons bereit stellst. Button23 wird sich nicht weiter als 3 Zellen ausdehnen können. Du musst also mehr Zellen bereit stellen und die Buttons sich entsprechend ausdehnen lassen.
 
W

Waynes

Gast
Ist das eigentlich normal, dass ich mit constraints.ipady die Höhe der Buttons etc... festlegen kann? Das ist ja wie nulllayout :p nur geht eben der Resize net hehe
 
Status
Nicht offen für weitere Antworten.
Ähnliche Java Themen
  Titel Forum Antworten Datum
R Welchen Layout Manager/ Wie strukturieren? AWT, Swing, JavaFX & SWT 14
P Swing welchen Layout Manager verwenden AWT, Swing, JavaFX & SWT 9
J LayoutManager Welchen Layout/Design-Manager? AWT, Swing, JavaFX & SWT 4
S Welches Java Layout sollte ich verwenden? AWT, Swing, JavaFX & SWT 3
S Layout - Problem AWT, Swing, JavaFX & SWT 1
D Layout einer scene mit ListView Elementen und Zwei Textfeldern AWT, Swing, JavaFX & SWT 1
H Swing , GridLayout, Größenbestimmung der Komponenten im Layout AWT, Swing, JavaFX & SWT 8
melaniemueller Layout wechseln über RadioButtons AWT, Swing, JavaFX & SWT 4
E LayoutManager Welcher Layout-Mix löst mein Problem? AWT, Swing, JavaFX & SWT 3
J Swing Hilfe bei Layout AWT, Swing, JavaFX & SWT 2
R Layered Layout AWT, Swing, JavaFX & SWT 1
E showAndWait is not allowed during animation or layout processing Memory FX AWT, Swing, JavaFX & SWT 2
newJavaGeek Grid-Layout problem AWT, Swing, JavaFX & SWT 7
E Swing Layout während der Laufzeit anpassen AWT, Swing, JavaFX & SWT 3
P JavaFX Zugriff auf Fenster/Layout-Container in eigenen Klassen AWT, Swing, JavaFX & SWT 5
R Layout Manager null und Component wird nicht hinzugefügt AWT, Swing, JavaFX & SWT 3
S Kann javafx.scene.layout.VBoxBuilder nicht importieren AWT, Swing, JavaFX & SWT 3
OSchriever Layout über Radiobuttons ändern AWT, Swing, JavaFX & SWT 4
B Swing Probleme mit dem Layout AWT, Swing, JavaFX & SWT 1
Hatsi09 JButton text layout AWT, Swing, JavaFX & SWT 9
I JavaFX - festes Layout AWT, Swing, JavaFX & SWT 1
S JavaFX TableView einzelne Zelle Layout zuweisen AWT, Swing, JavaFX & SWT 3
DaCrazyJavaExpert Swing Zwei gleichgroße Panels in einem Scrollpane mit Layout AWT, Swing, JavaFX & SWT 9
Neumi5694 Swing Card-Layout, Fokus AWT, Swing, JavaFX & SWT 2
kilopack15 Interface mit Layout verknüpfen AWT, Swing, JavaFX & SWT 2
Y Layout/Ausrichtungsprobleme AWT, Swing, JavaFX & SWT 4
T JavaFX Custom Layout AWT, Swing, JavaFX & SWT 5
A GUI Layout AWT, Swing, JavaFX & SWT 11
A Layout-Manager, JScrollPane, ... Chaos AWT, Swing, JavaFX & SWT 5
L wie Layout-Grid in JXPanel anzeigen? AWT, Swing, JavaFX & SWT 5
L Eigene Component Layout AWT, Swing, JavaFX & SWT 4
Soloeco LayoutManager Wie und welches Layout nutze ich am Besten? AWT, Swing, JavaFX & SWT 13
M LayoutManager Modalen JDialog ein Layout zuweisen AWT, Swing, JavaFX & SWT 3
M LayoutManager Layout reagiert nicht auf Constraints AWT, Swing, JavaFX & SWT 4
IsSchoGuat LayoutManager Layout-Containergrösse AWT, Swing, JavaFX & SWT 4
F GridBag Layout AWT, Swing, JavaFX & SWT 1
Z Absolutes Layout / Kontrolle über Anordnung AWT, Swing, JavaFX & SWT 3
M Mehrere Jpanel in einem JScrollPane (Layout) AWT, Swing, JavaFX & SWT 2
M Layout-Probleme unter Swing AWT, Swing, JavaFX & SWT 5
D LayoutManager GUI skalieren und deren Komponenten mit Grid(Bag)Layout-Manager. AWT, Swing, JavaFX & SWT 5
J ComboBoxModel addElement verändert Layout AWT, Swing, JavaFX & SWT 8
E Probelm mit Layout AWT, Swing, JavaFX & SWT 1
B Hilfe welches Layout brauch ich AWT, Swing, JavaFX & SWT 4
P Tipps für GUI-Layout AWT, Swing, JavaFX & SWT 2
M Passender Layout-Manager AWT, Swing, JavaFX & SWT 3
M LayoutManager Layout zur Laufzeit ändern AWT, Swing, JavaFX & SWT 8
N Swing Zweifarbiges Layout für den Filechooser AWT, Swing, JavaFX & SWT 12
B LayoutManager Card Layout AWT, Swing, JavaFX & SWT 2
E Angehängtes Layout, aber wie? AWT, Swing, JavaFX & SWT 12
1 Eigenes Layout schreiben AWT, Swing, JavaFX & SWT 4
B SWT layout invalidieren in SWT? AWT, Swing, JavaFX & SWT 4
J Layout: oben 20% unten 80% AWT, Swing, JavaFX & SWT 12
T Layout für Listendarstellung AWT, Swing, JavaFX & SWT 3
F LayoutManager Null-Layout unter Linux im TreeCellEditor AWT, Swing, JavaFX & SWT 3
K Eclipse Layout (Gimp Layout, Tiled Layout...) AWT, Swing, JavaFX & SWT 4
C LayoutManager Passendes Layout gesucht AWT, Swing, JavaFX & SWT 2
M Layout funktioniert nicht AWT, Swing, JavaFX & SWT 3
dzim Layout von Panes in JFX2 AWT, Swing, JavaFX & SWT 17
H Layout Idee AWT, Swing, JavaFX & SWT 8
M Swing Dynamisches Layout AWT, Swing, JavaFX & SWT 10
J LayoutManager Komponentenaustausch zerschießt Layout AWT, Swing, JavaFX & SWT 4
F Layout-Problem AWT, Swing, JavaFX & SWT 2
K Gui Layout Frage AWT, Swing, JavaFX & SWT 5
B Anderen Layout-Manager verwenden AWT, Swing, JavaFX & SWT 17
E Null-Layout - Wie geht es ohne? AWT, Swing, JavaFX & SWT 19
Furtano AWT mehrere Bilder in einen Frame zeichnen + Layout Manager AWT, Swing, JavaFX & SWT 10
L Swing dynamisches Image-Panel in Layout einbinden AWT, Swing, JavaFX & SWT 10
D Bild in JPanel verschiebt Layout. Wie fixieren? AWT, Swing, JavaFX & SWT 9
GUI-Programmer Wieder ne Layout Frage AWT, Swing, JavaFX & SWT 11
GUI-Programmer LayoutManager Kurze Layout Frage - eine komponente mittig? AWT, Swing, JavaFX & SWT 5
D Problem mit 3-Spalten Layout AWT, Swing, JavaFX & SWT 17
ARadauer Wenig Material zum Thema: Design, Layout, Usability von Swing Anwendungen AWT, Swing, JavaFX & SWT 11
S LayoutManager Welcher LayoutManager für dieses zweispaltige Layout? AWT, Swing, JavaFX & SWT 13
G LayoutManager Layout welches von Links nach rechts anordnet mit TOP Alignment! AWT, Swing, JavaFX & SWT 5
A Best practice für konkretes Layout AWT, Swing, JavaFX & SWT 10
G LayoutManager Layout für Spalten AWT, Swing, JavaFX & SWT 8
A Layout/JPanelgröße AWT, Swing, JavaFX & SWT 6
S pack() bei null-Layout AWT, Swing, JavaFX & SWT 10
C SWT Tabellen-Layout in StyledText? AWT, Swing, JavaFX & SWT 6
R Swing Layout setzen AWT, Swing, JavaFX & SWT 3
L Layout automatische Anpassung umgehen? AWT, Swing, JavaFX & SWT 5
A Problem mit Layout-Manager AWT, Swing, JavaFX & SWT 11
J Button Layout anpassen AWT, Swing, JavaFX & SWT 22
H LayoutManager Layout mit GridBagLayout machbar? AWT, Swing, JavaFX & SWT 6
B Buttongröße im Layout AWT, Swing, JavaFX & SWT 4
B LayoutManager Layout Problem AWT, Swing, JavaFX & SWT 14
O LayoutManager Layout entwerfen AWT, Swing, JavaFX & SWT 3
A diverse Layout-Fragen AWT, Swing, JavaFX & SWT 4
F LayoutManager Eigenes Layout die Lösung?! AWT, Swing, JavaFX & SWT 4
dzim SWT Layout mit Sections aus Eclipse Forms AWT, Swing, JavaFX & SWT 17
F JScrollPane verwirft Layout von JPanel AWT, Swing, JavaFX & SWT 2
C LayoutManager Layout und vergrößern des Frames AWT, Swing, JavaFX & SWT 5
E Swing Runde Buttons / Position eines Obj. im Layout AWT, Swing, JavaFX & SWT 7
S Swing UI-Elemente ordnen sich ungewollt in einer Reihe (ohne Layout) AWT, Swing, JavaFX & SWT 5
A Ungewollte Layout änderungen AWT, Swing, JavaFX & SWT 3
A Suche: Eclipse-GUI-Layout AWT, Swing, JavaFX & SWT 5
E JPanel mit Null Layout entfernt Buttons AWT, Swing, JavaFX & SWT 11
N Swing Layout positionieren AWT, Swing, JavaFX & SWT 2
B Methode setzt nicht das Layout in einer if-Abfrage AWT, Swing, JavaFX & SWT 13
H LayoutManager Dynamisches Layout AWT, Swing, JavaFX & SWT 3

Ähnliche Java Themen

Neue Themen


Oben