六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 85|回复: 0

请教:如何使增加在JPanel中的不同长度的JList顶部对齐?

[复制链接]

升级  20%

2

主题

2

主题

2

主题

童生

Rank: 1

积分
10
 楼主| 发表于 2013-2-5 01:21:41 | 显示全部楼层 |阅读模式
如题:如何使增加在JPanel中的不同长度的JList顶部对齐,而非垂直居中对齐?

示例代码如下:
import javax.swing.JFrame;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;

public class testPanel extends JPanel {

public testPanel(){
super();
}

public static void main(String[] args){
JFrame frame = new JFrame();
JPanel panel = new testPanel();
panel.add(new JList(webSites1));
panel.add(new JList(webSites2));
panel.add(new JList(webSites3));
JScrollPane pane = new JScrollPane(panel);
frame.getContentPane().add(pane);
frame.setSize(800, 600);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}


static String webSites1[] = {
        "1About Portal", "AltaVista Search", "Amazon Shopping", "Andale Shopping", "Any Day Calendar", "AOL Instant Messager", "Ask Jeeves", "Auctions", "BigStep Small Business", "BizRate Surveys",
        "BizTravel", "Brittanica", "C|Net Technology", "Carnegie Mellon University", "CBS Sportsline", "CenterBeam Business", "Charles Schwab", "Chumbo Computer Shopping", "DealTime Shopping", "Deep Canyon Research",
        "Deja Opinions", "Dell Computer", "DevEdge Web Development", "DirectHit Search", "Discovery Channel for Kids", "Disney", "eBay Auctions", "eFax", "eHobbies", "eHow Do I ...?",
    };

static String webSites2[] = {
        "2PowWow Instant Messaging", "Productopia Shopping", "Quicken", "RealNetworks Streaming Media", "Remarq Collaboration Services", "Royal Institute of Technology", "Scour Media Search", "See U There Organizing", "Service 911 Computer Help", "SlashDot",
        "SmartAge Business", "Stamps", "Super Family Exchange", "Surf Monkey Kids Channel", "Swedish Institute of Computer Science", "Talk City Online Communities", "TD Waterhouse", "The Street Financial", "Topica Mailing Lists", "University of Maryland",
        
    };

static String webSites3[] = {
        "2PowWow Instant Messaging", "Productopia Shopping", "Quicken", "RealNetworks Streaming Media", "Remarq Collaboration Services", "Royal Institute of Technology", "Scour Media Search", "See U There Organizing", "Service 911 Computer Help", "SlashDot",
        "SmartAge Business", "Stamps", "Super Family Exchange", "Surf Monkey Kids Channel", "Swedish Institute of Computer Science", "Talk City Online Communities", "TD Waterhouse", "The Street Financial", "Topica Mailing Lists", "University of Maryland",
        "Brittanica", "C|Net Technology",
    };
}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表