java jlist 添加滚动条_java中向JList添加滚动条的问题!急~~~

我的源文件是这样的:有两个文件:Application1.java和Frame1.java其中:Application.java如下:packagejlist_test;importjavax.swing.UIManager;importjava.awt.*;/***

Title:

...

我的源文件是这样的:有两个文件:Application1.java和Frame1.java

其中:Application.java如下:

package jlist_test;

import javax.swing.UIManager;

import java.awt.*;

/**

*

Title:

*

Description:

*

Copyright: Copyright (c) 2007

*

Company:

* @author not attributable

* @version 1.0

*/

public class Application1 {

boolean packFrame = false;

//Construct the application

public Application1() {

Frame1 frame = new Frame1();

//Validate frames that have preset sizes

//Pack frames that have useful preferred size info, e.g. from their layout

if (packFrame) {

frame.pack();

}

else {

frame.validate();

}

//Center the window

Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();

Dimension frameSize = frame.getSize();

if (frameSize.height > screenSize.height) {

frameSize.height = screenSize.height;

}

if (frameSize.width > screenSize.width) {

frameSize.width = screenSize.width;

}

frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);

frame.setVisible(true);

}

//Main method

public static void main(String[] args) {

try {

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());

}

catch(Exception e) {

e.printStackTrace();

}

new Application1();

}

}

Frame1.java如下:

package jlist_test;

import java.awt.*;

import java.awt.event.*;

import javax.swing.*;

import com.borland.jbcl.layout.*;

/**

*

Title:

*

Description:

*

Copyright: Copyright (c) 2007

*

Company:

* @author not attributable

* @version 1.0

*/

public class Frame1 extends JFrame {

JPanel contentPane;

XYLayout xYLayout1 = new XYLayout();

//JList jList1 = new JList();

String[] str = {"Math","English","Physics","Chemic","Biology","Politics"};

JList jList1 = new JList(str);

JScrollPane listScrollPane = new JScrollPane(jList1);

//Construct the frame

public Frame1() {

enableEvents(AWTEvent.WINDOW_EVENT_MASK);

try {

jbInit();

}

catch(Exception e) {

e.printStackTrace();

}

}

//Component initialization

private void jbInit() throws Exception {

contentPane = (JPanel) this.getContentPane();

contentPane.setLayout(xYLayout1);

this.setSize(new Dimension(400, 300));

this.setTitle("Frame Title");

jList1.setVisibleRowCount(4);

contentPane.add(jList1, new XYConstraints(72, 86, 213, 73));

}

//Overridden so we can exit when window is closed

protected void processWindowEvent(WindowEvent e) {

super.processWindowEvent(e);

if (e.getID() == WindowEvent.WINDOW_CLOSING) {

System.exit(0);

}

}

}

但是在显示出来的列表框中却找不到滚动条的踪影,请问是哪里出了问题,请高手帮忙解决一下,谢谢!用List可以产生滚动条!

展开

  • 0
    点赞
  • 0
    收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
©️2022 CSDN 皮肤主题:数字20 设计师:CSDN官方博客 返回首页
评论

打赏作者

简在我心

你的鼓励将是我创作的最大动力

¥2 ¥4 ¥6 ¥10 ¥20
输入1-500的整数
余额支付 (余额:-- )
扫码支付
扫码支付:¥2
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值