我做了一个简单的Java的Swing 界面,可是我在每一个JPanel 容器中添加上控件之后,控件的大小却是不能控制,请问有什么方法可以调整吗?
import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.EmptyBorder; import javax.swing.table.DefaultTableModel; public class ListCustomTypeFile extends JFrame { private JPanel contentPane = new JPanel(new GridLayout(3,1)); private JLabel URILabel = new JLabel(); private JButton chooserButton = new JButton("选择文件夹"); private JLabel messLabel = new JLabel("载入指定文件扩展名称"); private JTextField nameTextFile = new JTextField(); private JScrollPane scroolPane = new JScrollPane(); private JTable table =new JTable(); private DefaultTableModel tableModel = new DefaultTableModel(); public ListCustomTypeFile() { this.setTitle("显示指定类型的文件"); this.setVisible(true); this.setLocationRelativeTo(null); this.setSize(650, 550); this.setContentPane(contentPane); contentPane.setBorder(new EmptyBorder(5,5,5,5)); JPanel panel1 = new JPanel(new GridLayout(1,2)); panel1.add(chooserButton); panel1.add(URILabel); contentPane.add(panel1); JPanel panel2 = new JPanel(new GridLayout(1,2)); panel2.add(messLabel); panel2.add(nameTextFile); contentPane.add(panel2); JPanel panel3 = new JPanel(new BorderLayout()); panel2.add(scroolPane,BorderLayout.CENTER); scroolPane.setViewportView(table); } public static void main(String[] args) { // TODO Auto-generated method stub new ListCustomTypeFile(); }
因为网速不行,所以截图上传不了,望各位高手解答
1 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
java的CS程序,建议使用netbeans开发,在netbeans上控件可以直接拖拽的(有点像C#的winform),用这个比起自己写窗体方便多了,也不会出现这些BUG了。
添加回答
举报
0/150
提交
取消