Чтобы создать мой графический интерфейс, я создал ряд подклассов jpanel , каждая из тех, кто решает конкретную проблему макета. внутренний с Boxlayout для распределения компонентов по предпочтительному способу, внешней с пограничным для сжатия компонентов в их минимальное измерение. Titleborder , внутренний, который приведен в конструкторе и цель которого - настроить макет внутри зоны Fieldset . Недавно мне нужно было использовать их обоих: я хотел, чтобы jbutton и jtextarea отображался на другой, не будучи искусственно расширенным (то есть внутри altboxlayout_jpanel ) и окруженной границей (то есть. Поскольку все мои компоненты уже были проверены, я был уверен, что это будет хорошо. Я знаю, что это там (я проверил), и я предполагаю, что это покрывается JTextArea , но у меня нет дополнительной информации. Ниже приведен мой код. < /P>
Любая помощь в спасении моего Jbutton < /code> была бы очень оценена! < /P>
public class StackOverflowQuestion extends JFrame {
private static final long serialVersionUID = -5644282466098799568L;
private JPanel contentPanel;
// Display area
private Fieldset fieldset;
private JButton button;
private JTextArea jTextArea;
/**
* Create the frame.
*/
public StackOverflowQuestion() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setBounds(100, 100, 300, 140);
contentPanel = new JPanel();
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
contentPanel.setLayout(new BorderLayout(0, 0));
setContentPane(contentPanel);
// Testing new components
// JPanel fieldsetLayoutPanel = new JPanel();
// BoxLayout fieldsetLayout = new BoxLayout(fieldsetLayoutPanel, BoxLayout.PAGE_AXIS);
// fieldsetLayoutPanel.setLayout(fieldsetLayout);
JPanel fieldsetLayoutPanel_2 = new AltBoxLayout_JPanel(BoxLayout.PAGE_AXIS);
this.fieldset = new Fieldset("Fieldset title", fieldsetLayoutPanel_2, null);
this.button = new JButton("Button text");
this.jTextArea = new JTextArea("JTextArea here!");
this.jTextArea.setRows(5);
this.jTextArea.setColumns(20);
this.button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
System.out.println("Action executed: " + arg0.toString());
}});
fieldset.add(button);
fieldset.add(jTextArea);
contentPanel.add(fieldset);
System.out.println("Analysis of the components of the contentPanel:");
analyzeLayoutsOfComponentAndSubComponents(contentPanel, 0);
pack();
}
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
StackOverflowQuestion frame = new StackOverflowQuestion();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/** A method that studies the {@link JPanel} and its sub-{@link JPanel}s, iterating through all the component tree.
*
* @param c
* @param tab
*/
public static void analyzeLayoutsOfComponentAndSubComponents(JPanel c, int tab) {
System.out.println(repeatChar('\t', tab) + c.toString());
for(int i=0 ; i
Подробнее здесь: https://stackoverflow.com/questions/629 ... -interface
Проблема видимости в моем пользовательском пользовательском интерфейсе ⇐ JAVA
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Можете ли вы создать область видимости, которая вызывает различные другие области видимости?
Anonymous » » в форуме Php - 0 Ответы
- 38 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Можете ли вы создать область видимости, которая вызывает различные другие области видимости?
Anonymous » » в форуме Php - 0 Ответы
- 45 Просмотры
-
Последнее сообщение Anonymous
-