java jlist_Java JList.setListData方法代码示例

import javax.swing.JList; //导入方法依赖的package包/类

/**

* Creates an instance of this class.

* @param menu the menu that will be edited by the user

* @param indexOffset the offset of the editable area

* @param indexLimit the limit of the editable area

*/

public MenuManagementWindow(JMenu menu,int indexOffset,int indexLimit) {

this.setBounds(250,200,400,300);

this.setTitle("Menu management");

this.setResizable(false);

this.setModal(true);

this.managedMenu = menu;

this.emptyMenu = false;

this.offset = indexOffset;

this.limit = indexLimit;

itemsList = buildListFromComponents(

trimComponentsByOffsets(menu.getMenuComponents(),offset,limit)

);

removedItemsList = new JList();

removedItemsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

removedItemsList.setListData(removedItems = new Vector());

removedItemsList.setSize(100,200);

buildButtons();

JPanel okCancelPanel = new JPanel(new FlowLayout());

okCancelPanel.add(okButton);

okCancelPanel.add(cancelButton);

JPanel separatorButtonsPanel = new JPanel(new FlowLayout());

separatorButtonsPanel.setBorder(BorderFactory.createTitledBorder("Separator"));

separatorButtonsPanel.add(insertSeparatorButton);

separatorButtonsPanel.add(removeSeparatorButton);

JPanel itemsPanel = new JPanel();

itemsPanel.setLayout(new BoxLayout(itemsPanel,BoxLayout.Y_AXIS));

itemsPanel.setPreferredSize(new Dimension(175,200));

itemsPanel.add(new JLabel("Menu items:"));

JScrollPane listScroll = new JScrollPane(itemsList);

itemsPanel.add(listScroll);

itemsPanel.add(separatorButtonsPanel);

JPanel removedItemsPanel = new JPanel();

removedItemsPanel.setLayout(new BoxLayout(removedItemsPanel,BoxLayout.Y_AXIS));

removedItemsPanel.setPreferredSize(new Dimension(175,200));

removedItemsPanel.add(new JLabel("Removed items:"));

JScrollPane removedListScroll = new JScrollPane(removedItemsList);

removedItemsPanel.add(removedListScroll);

JPanel itemsButtonsPanel = new JPanel();

itemsButtonsPanel.setLayout(new BoxLayout(itemsButtonsPanel,BoxLayout.Y_AXIS));

itemsButtonsPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

itemsButtonsPanel.add(removeItemButton);

itemsButtonsPanel.add(retrieveButton);

JPanel centerPanel = new JPanel();

centerPanel.setLayout(new BoxLayout(centerPanel,BoxLayout.X_AXIS));

centerPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));

centerPanel.add(itemsPanel);

centerPanel.add(itemsButtonsPanel);

centerPanel.add(removedItemsPanel);

JPanel southPanel = new JPanel(new BorderLayout());

southPanel.add(okCancelPanel,BorderLayout.EAST);

this.getContentPane().setLayout(new BorderLayout());

this.getContentPane().add(centerPanel,BorderLayout.CENTER);

this.getContentPane().add(southPanel,BorderLayout.SOUTH);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值