为什么JScrollPane不能够被显示出来?

最近碰到一个棘手的问题写了一个swing程序,用到JCrollPane组建,初始是调用其setVisible(false),在程序的后端会在调用其setVisible(true),但是不能显示出来,不知道是何缘故!

下面是程序代码:
public class AlertFrame extends JFrame implements ActionListener{

private static final long serialVersionUID = 1L;
private static int count = 1;
private JTextArea detailTxa;
private JScrollPane jScrollPane1;
private JLabel errolLbl;
private JButton cancelBtn;
private JButton detailBtn;
private String simpleMsg = "";
private String detailMsg = "";
public AlertFrame(){
super();
}
public AlertFrame(String simpleMsg,String detailMsg){
super("系统消息");
this.simpleMsg = simpleMsg;
this.detailMsg = detailMsg;
init();

}
public void init(){
WindowUtilities.setNativeLookAndFeel();
setSize(480,260);
setResizable(true);
Box box = new Box(BoxLayout.Y_AXIS);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setLayout(new BorderLayout());
JPanel centerPanel = new JPanel(new BorderLayout());
Box centerBox = new Box(BoxLayout.X_AXIS);
centerBox.add(new JLabel(" "));
errolLbl = new JLabel(simpleMsg);
centerBox.add(errolLbl);
centerBox.add(new JLabel(" "));
JLabel titleLbl = new JLabel(" 系统消息 ");
centerPanel.add(centerBox, BorderLayout.CENTER);
centerPanel.add(titleLbl, BorderLayout.NORTH);
JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
cancelBtn = new JButton(" 取消 ");
cancelBtn.addActionListener(this);
detailBtn = new JButton("详细信息>>");
detailBtn.addActionListener(this);
bottomPanel.add(cancelBtn);
bottomPanel.add(detailBtn);
centerPanel.add(bottomPanel , BorderLayout.SOUTH);
detailTxa = new JTextArea(10,25);
detailTxa.setText(detailMsg);
detailTxa.setVisible(false);

jScrollPane1 = new JScrollPane(detailTxa);
jScrollPane1.setVisible(false);
box.add(centerPanel);
box.add(jScrollPane1);
this.add(box);
setVisible(true);
}
public void actionPerformed(ActionEvent e) {
if(e.getSource() == cancelBtn){
this.dispose();
}else{
if((count%2) == 0){
this.jScrollPane1.setVisible(false);
count++;
}
else{
this.jScrollPane1.setVisible(true);
count++;
}
}
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值