Salve,
syo avendo delle difficoltà nel posizionare degli oggetti all'interno di un frame. Io avevo usato un BorderLayout, ma il risultato è totalmente sbagliato. Sicuramente devo usare altri layout, ma sinceramente sono poco pratico con il loro utilizzo.
Il codice base è il seguente:
e avrei bisogno che la combo e il button fossero al centro del frame.codice:import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JComboBox; import javax.swing.JButton;; public class SelectClassificationLevelFrame extends javax.swing.JFrame { private JButton _jButton; private JComboBox _jCombo; public SelectClassificationLevelFrame() { initComponents(); } private void initComponents() { this.setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); this.setSize(new Dimension(300, 300)); this.getContentPane().setLayout(new BorderLayout()); _jButton = new JButton(); _jButton.setText("OK"); this.getContentPane().add(_jButton, BorderLayout.SOUTH); String[] cmbItems = {"Testo1", "Testo2", "Testo3", "Testo4"}; _jCombo = new JComboBox(cmbItems); _jButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String toSend = (String)_jCombo.getSelectedItem(); System.out.println("Inviato: " + toSend); } }); this.getContentPane().add(_jCombo, BorderLayout.NORTH); this.setVisible(true); } public static void main(String[] args) { SelectClassificationLevelFrame sclf = new SelectClassificationLevelFrame(); } }
Avevo pensato ad un GridLayout, ma ho poco dimistichezza con il suo uso.
Qualche suggerimento???
Grazie

Rispondi quotando