Witajcie,
Piszę GUI i użyłem FlowLayouta. Kod GUI jest taki:
private static void createAndShowGUI() {
JFrame mainFrame = new JFrame("AvrAssistant");
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel avrTypePane = new JPanel(); // Panel
JLabel avrTypeText = new JLabel("Choose avr type: "); // Text do combobox
JComboBox<String> avrTypeBox = new JComboBox<String>(); // Combobox
avrTypeBox.addItem("ATmega8"); // To tylko tymczasowe zeby byla zawartosc
avrTypePane.setLayout(new FlowLayout());
avrTypePane.add(avrTypeText);
avrTypePane.add(avrTypeBox);
//avrTypePane.setPreferredSize(new Dimension(0, 30));
JTabbedPane adTabs = new JTabbedPane();
JLabel sample = new JLabel("Sample tab text");
adTabs.addTab("Fuses", null, sample, "Fuse-bits configuration");
mainFrame.add(avrTypePane, BorderLayout.NORTH);
mainFrame.add(adTabs, BorderLayout.CENTER);
mainFrame.pack();
mainFrame.setVisible(true);
}
Efekt jest taki, że gdy ComboBox nie ustawi się obok Label to jest ucinany.
PS. Referencje typu avrTypePane, mainFrame itp. umieszczać jako atrybuty klasy, żeby inne funkcje obsługujące zdarzenia mogły użyć, czy jak inaczej to mogę zrobić (jak się w praktyce/najczęściej to robi)?