【求助】 怎么给JList加一个纵向滚动条? 当数据多出了范围的时候自动会有滚动条。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 import java.awt.AWTEvent;import java.awt.Dimension;import java.awt.event.WindowEvent;import javax.swing.JFrame;import javax.swing.JList;import javax.swing.JPanel;import javax.swing.JScrollPane;public class Frame1 extends JFrame { JPanel contentPane; //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(30, 100)); this.setTitle("Frame Title"); jList1.setVisibleRowCount(4); //contentPane.add(jList1, new XYConstraints(72, 86, 213, 73)); contentPane.add(listScrollPane); } //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); } }}import javax.swing.UIManager;import java.awt.*;/** * @author qzw */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(); }} 请高手帮忙给我看看gui 请问有java 操作visio 的函数库吗? jtabel 显示问题 一个关于数据交换的算法,不理解,高手解释一下! 高手请进 Java初学者CSDN第3问! 谁碰到过这种诡异的事情?谢谢啦!!!!!!!!!! 同一个Package内的class,有时候可以默认访问,有时候又不行 界面显示的问题 java doom4j怎么解析xml下同一根节点的相同子节点 JTable不能显示汉字的问题,请高手指教啊,详细描述如内文,谢谢 Java如何获得当前程序的CPU、内存使用情况?
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.event.WindowEvent;import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
public class Frame1 extends JFrame {
JPanel contentPane;
//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(30, 100));
this.setTitle("Frame Title");
jList1.setVisibleRowCount(4);
//contentPane.add(jList1, new XYConstraints(72, 86, 213, 73));
contentPane.add(listScrollPane);
}
//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);
}
}
}
import javax.swing.UIManager;
import java.awt.*;/**
* @author qzw
*/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();
}
}