问题描述
是否可以在Java中向下移动表格.我尝试了setBorder
,setLocation
,...,但是没有用.我该怎么办?
Is it possible to move a table downward in Java. I tried setBorder
, setLocation
, ... but it didn't work. What should I do?
JLabel label = new JLabel("Enter proper data: ");
label.setBounds(0, 0, 120, 50);
frame.add(label);
JButton btn = new JButton("Click");
btn.setBounds(100, 300, 80, 50);
frame.add(btn);
String data [][] = new String [6][4];
String column[]={"No.","Player 1","Player 2","Strategy"};
JTable table = new JTable(data, column);
JScrollPane sp=new JScrollPane(table);
frame.add(sp);
frame.setSize(300,400);
frame.setVisible(true);
请看这张图片:
推荐答案
对于外部面板的BorderLayout
看起来不错(蓝色轮廓线).红色大标签位于PAGE_START
中,表的(滚动窗格)位于CENTER
中.
Looks good for a BorderLayout
for the outer panel (outlined in blue). The big red label goes in the PAGE_START
and the (scroll pane of the) table goes in the CENTER
.
将按钮放在边框布局的PAGE_END
中带有FlowLayout
(居中)的面板中,该面板带有红色轮廓.完毕.
Put the button in a panel with a FlowLayout
(centered), the panel with the red outline, in the PAGE_END
of the border layout. Done.
所有额外的高度(如果用户使GUI更大)将被赋予表格.
All extra height (if the user makes the GUI bigger) will be given to the table.
这篇关于如何在Java中向下移动表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!