Почти получилось, осталась проблема с высотой. Что надо прописать для JPanel, чтобы он по мере добавления компонентов сам менял высоту?
| Код | public class TInput extends javax.swing.JPanel { final JPanel topPanel, bottomPanel, mainPanel;
public TInput() {
initComponents();
mainPanel = new JPanel(); bottomPanel = new JPanel(new FlowLayout()); topPanel = new JPanel(new GridLayout(0, 1)); bottomPanel.add(new JButton("Ok")); bottomPanel.add(new JButton("Cancel"));
setLayout(new GridLayout(0, 1)); add(mainPanel); mainPanel.setBackground(Color.white);
Box panel = Box.createVerticalBox(); mainPanel.add(panel); panel.add(topPanel); panel.add(bottomPanel); panel.setVisible(true);
for (int i = 0; i < 10; i++) { JTextField o = new JTextField(); topPanel.add(o); o.setSize(100, 20); }
}
|
Вот так выходит, если менять количество JTextField

|