[英]Java swing Border and Boxlayout
i have a Jtable and now i want to have a JLabel and a JTextField and a JButton in one row above this Jtable. 我有一个Jtable,现在我想在此Jtable上方的一行中有一个JLabel和一个JTextField和一个JButton。
How do i do that? 我怎么做?
until now i had this: 直到现在我有这个:
final JTableHeader header = table.getTableHeader();
setLayout(new BorderLayout());
add(header, BorderLayout.PAGE_START);
add(table, BorderLayout.CENTER);
now i added this above: 现在我在上面添加了这个:
ImageIcon leftButtonIcon = createImageIcon("images/add.gif");
JButton addButton = new JButton(leftButtonIcon);
JLabel labelF = new JLabel("Filter:");
labelF.setAlignmentX(Component.RIGHT_ALIGNMENT);
JTextField eingabeF = new JTextField();
eingabeF.setSize(50, 10);
but how to do, that there ist this: "Filter: TEXTFIELD BUTTON" and under this there is the Table ? 但是怎么做,有这个:“ Filter:TEXTFIELD BUTTON”,在这个下面有Table?
labelF
label, eingabeF
text field and addButton
button to an instance of JPanel
with FLowLayout
. labelF
标签, eingabeF
文本字段和addButton
按钮添加到具有FLowLayout
的JPanel
实例。 And add it to the content pane(which has BorderLayout
) with constraint BorderLayout.PAGE_START
. BorderLayout
与约束) BorderLayout.PAGE_START
。 JPanel
has FlowLayout
as it's default layout JPanel
具有FlowLayout
作为其默认布局 Enclose your table to an instance of JScrollPane
and Then add the scroll pane to the content pane with constraint BorderLayout.CENTER
. 将表包含到
JScrollPane
的实例中,然后将滚动窗格添加到具有BorderLayout.CENTER
约束的内容窗格中。 The scroll pane automatically places the table header at the top of the viewport. 滚动窗格会自动将表标题放置在视口的顶部。
JScrollPane scrollPane = new JScrollPane(table); table.setFillsViewportHeight(true);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.