如何在Java中向下移动表格? [英] How can I move a table downward in Java?

查看:69
本文介绍了如何在Java中向下移动表格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Java中向下移动表格.我尝试了setBordersetLocation,...,但是没有用.我该怎么办?

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中向下移动表格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆