Ancora problemi con il GridBagLyout.
Utilizzando il .setMinimumSize su alcuni componenti, sono riuscito a sistemarmi l'interfaccia grafica su un pannello come mi piace.
Il problema arriva quando faccio la stessa cosa su un secondo pannello, i cui componenti sono disposti allo stesso identico modo (cambiano solo le descrizioni e le funzioni).
Ho fatto il secondo codice con ctrl+C e ctrl+V, cambiando i nomi. Ma nel secondo pannello le dimensioni dei componenti sono un po' a caso.
Ci metto qualche spezzone di codice
(Questo funziona come voglio)
... e così via. Aggiungo solo altri bottoni e una JTextAreacodice:panel1 = new JPanel(); panel1.setLayout( new GridBagLayout() ); GridBagConstraints c = new GridBagConstraints(); String element1[] = new String[0]; elenco1 = new JComboBox( element1 ); elenco1.setMaximumRowCount( 5 ); elenco1.addItemListener( this ); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.gridheight = 1; c.gridwidth = 3; c.insets = new Insets(10, 10, 5, 10); panel1.add( elenco1, c); String element2[] = new String[0]; lista1 = new JList( element2 ); lista1.setVisibleRowCount( 5 ); lista1.setSelectionMode( ListSelectionModel.SINGLE_SELECTION ); lista1.addListSelectionListener( this ); scrollerlista1 = new JScrollPane( lista1, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollerlista1.setMinimumSize( new Dimension( 150, 100) ); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.gridheight = 3; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.insets = new Insets(5, 10, 5, 5); panel1.add( scrollerlista1, c); button1 = new JButton( "Firma" ); button1.addActionListener( this ); button1.setMinimumSize( dimButton ); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHWEST; c.gridx = 1; c.gridy = 1; c.gridheight = 1; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.insets = new Insets(5, 5, 4, 5); panel1.add( button1, c);
Invece, questo codice non mi da lo stesso risultato
Inutile dire che è la quarta o quinta volta che gioco al "cerca le differenze tra i due codici" e non trovo la soluzione.codice:panel2 = new JPanel(); panel2.setLayout( new GridBagLayout() ); GridBagConstraints c = new GridBagConstraints(); String element1[] = new String[0]; elenco2 = new JComboBox( element1 ); elenco2.setMaximumRowCount( 5 ); elenco2.addItemListener( this ); c.fill = GridBagConstraints.HORIZONTAL; c.gridx = 0; c.gridy = 0; c.gridheight = 1; c.gridwidth = 3; c.weightx = 1; c.weighty = 0; c.insets = new Insets(10, 10, 5, 10); panel2.add( elenco2, c); String element2[] = new String[0]; lista2 = new JList( element2 ); lista2.setVisibleRowCount( 5 ); lista2.setSelectionMode( ListSelectionModel.MULTIPLE_INTERVAL_SELECTION ); lista2.addListSelectionListener( this ); scrollerlista2 = new JScrollPane( lista2, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); scrollerlista2.setMinimumSize( new Dimension( 150, 100) ); c.fill = GridBagConstraints.NONE; c.gridx = 0; c.gridy = 1; c.gridheight = 3; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.insets = new Insets(5, 10, 5, 5); panel2.add( scrollerlista2, c); button2 = new JButton( "Crea Pacchetto" ); button2.addActionListener( this ); button2.setMinimumSize( dimButton ); c.fill = GridBagConstraints.NONE; c.anchor = GridBagConstraints.NORTHWEST; c.gridx = 1; c.gridy = 1; c.gridheight = 1; c.gridwidth = 1; c.weightx = 0; c.weighty = 0; c.insets = new Insets(5, 5, 4, 5); panel2.add( button2, c);

Rispondi quotando
