求助:图形用户界面设计中关于设置边界
请各位大侠帮帮忙,看一下我程序中被注释掉的代码为什么不能正常得给组件设边界(去掉注释和加上注释差别很大)?import java.io.*;
import java.awt.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import javax.swing.event.*;
class setFrame
{
private String label[] = {"a","b","c","d","e","f","g","h","i","j","k","l","m","n","o",
"p","q","r","s","t","u","v","w","x","y","z","随机"};
private String choice[] = {"考研英语","六级词汇","四级词汇"};
private JButton button[] = new JButton[29];
public JPanel panel[] = new JPanel[4];
private JTextField jtf = new JTextField();
private JList jlist = new JList(choice);
public JTextArea jta = new JTextArea();
private String filename;
public setFrame()
{
panel[0] = new JPanel();
panel[0].setLayout(new BoxLayout(panel[0],BoxLayout.Y_AXIS));
//panel[0].setBorder(BorderFactory.createEmptyBorder(0,0,400,320));
panel[1] = new JPanel();
panel[1].setLayout(new BoxLayout(panel[1],BoxLayout.Y_AXIS));
//panel[1].setBorder(BorderFactory.createEmptyBorder(0,340,400,700));
//jlist.setBorder(BorderFactory.createEmptyBorder(10,10,20,320));
jlist.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
jlist.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
if(e.getValueIsAdjusting())
return;
filename = "E:\\" + (String)jlist.getSelectedValue()
+ ".txt";
}
});
//jlist.setAlignmentX(jlist.CENTER_ALIGNMENT);
//jlist.setAlignmentY(jlist.CENTER_ALIGNMENT);
panel[0].add(jlist);
panel[2] = new JPanel(new GridLayout(7,4,3,3));
panel[2].setBorder(BorderFactory.createTitledBorder("按字母查询"));
for(int i = 0; i < 27; i++)
{
button[i] = new JButton(label[i]);
panel[2].add(button[i]);
}
panel[0].add(panel[2]);
jtf.setBorder(BorderFactory.createTitledBorder("请输入待查询单词:"));
panel[0].add(jtf);
//jta.setBorder(BorderFactory.createEmptyBorder(0,340,200,700));
panel[1].add(jta);
button[27] = new JButton("下一条");
button[28] = new JButton("上一条");
panel[3] = new JPanel(new FlowLayout());
panel[3].add(button[27]);
panel[3].add(button[28]);
panel[1].add(panel[3]);
}
}
public class EnglishTest
{
public static void main(String args[])throws Exception
{
JFrame frame = new JFrame("单词测试");
Container container = frame.getContentPane();
container.setLayout(new BoxLayout(container,BoxLayout.X_AXIS));
setFrame setframe = new setFrame();
container.add(setframe.panel[0]);
container.add(setframe.panel[1]);
frame.setSize(700,400);
frame.setResizable(false);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent e)
{
int confirm = JOptionPane.showConfirmDialog(null,"是否立即退出系统?",
"提示信息",JOptionPane.OK_CANCEL_OPTION,JOptionPane.QUESTION_MESSAGE);
if(confirm == JOptionPane.OK_OPTION)
System.exit(0);
}
});
}
}