下面列出了javax.swing.JList#setBorder ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public void init() {
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS));
tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
for (PanelHolder p : panels)
p.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
list = new JList(new ListListModel(panels));
list.setBorder(BorderFactory.createEmptyBorder(5, 5 , 5, 5));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
list.addListSelectionListener(this);
list.setCellRenderer(renderer);
list.setSelectedIndex(0);
if (cellHeight != 0)
list.setFixedCellHeight(cellHeight);
JScrollPane scroll = new JScrollPane(list);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
split.setResizeWeight(0);
split.setDividerLocation(150);
add(split);
}
public void init() {
tableIcon = FormUtils.getIcon(tableIcon, DEFAULT_TABLE_ICON);
for (TableEditor<?> editor : editors)
editor.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list = new JList(editors);
list.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 0));
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(-1);
JScrollPane scroll = new JScrollPane(list);
split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, scroll, editorPanel);
getContentPane().add(split);
list.addListSelectionListener(this);
list.setCellRenderer(new ListCellRenderer());
list.setSelectedIndex(0);
setSize(800, 600);
}
private JList<License> createLicenseList(License[] licenses, final JTextArea textArea) {
final JList<License> result = new JList<>(licenses);
result.setBorder(new LineBorder(Color.darkGray, 1));
result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
result.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
textArea.setText(result.getSelectedValue().getLicenseText());
textArea.setCaretPosition(0);
}
});
result.setSelectedIndex(0);
return result;
}
private JList<License> createLicenseList(License[] licenses, final JTextArea textArea) {
final JList<License> result = new JList<>(licenses);
result.setBorder(new LineBorder(Color.darkGray, 1));
result.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
result.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
textArea.setText(result.getSelectedValue().getLicenseText());
textArea.setCaretPosition(0);
}
});
result.setSelectedIndex(0);
return result;
}
private void initUI(Component parent)
{
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
setSize(474, 225);
setLocationRelativeTo(parent);
setUndecorated(true);
JPanel contentPane = new JPanel();
contentPane.setBackground(Color.DARK_GRAY);
contentPane.setBorder(new LineBorder(new Color(128, 128, 128), 2));
setContentPane(contentPane);
contentPane.setLayout(new MigLayout("", "[255.00,grow][106.00,grow][grow]", "[][grow][]"));
WindowDragListener wdl = new WindowDragListener(50);
addMouseListener(wdl);
addMouseMotionListener(wdl);
JLabel lblTitle = new JLabel("Select a Group");
lblTitle.setFont(new Font("Tahoma", Font.PLAIN, 22));
lblTitle.setForeground(Color.WHITE);
contentPane.add(lblTitle, "gapx 15 0, cell 0 0");
CloseButton btnClose = new CloseButton(this, JFrame.DISPOSE_ON_CLOSE);
contentPane.add(btnClose, "cell 2 0,alignx right,gapx 0 15");
JScrollPane devicesScrollPane = new JScrollPane();
devicesScrollPane.setBorder(null);
devicesScrollPane.getHorizontalScrollBar().setUI(new ModernScrollBarUI());
devicesScrollPane.getVerticalScrollBar().setUI(new ModernScrollBarUI());
contentPane.add(devicesScrollPane, "cell 0 1 3 1,grow");
groupsModel = new DefaultListModel<String>();
JList<String> listGroups = new JList<String>(groupsModel);
listGroups.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
listGroups.setFont(new Font("Tahoma", Font.PLAIN, 20));
listGroups.setBackground(Color.DARK_GRAY);
listGroups.setBorder(new LineBorder(Color.GRAY));
listGroups.setForeground(Color.WHITE);
devicesScrollPane.setViewportView(listGroups);
JButton btnCreateGroup = new ModernButton("Delete Group");
btnCreateGroup.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
deleteGroup(listGroups.getSelectedValue());
}
});
contentPane.add(btnCreateGroup, "cell 2 2");
}
public PerformanceVectorViewer(final PerformanceVector performanceVector, final IOContainer container) {
setLayout(new BorderLayout());
// all criteria
final CardLayout cardLayout = new CardLayout();
final JPanel mainPanel = new JPanel(cardLayout);
add(mainPanel, BorderLayout.CENTER);
List<String> criteriaNameList = new LinkedList<>();
for (int i = 0; i < performanceVector.getSize(); i++) {
PerformanceCriterion criterion = performanceVector.getCriterion(i);
criteriaNameList.add(criterion.getName());
JPanel component = ResultDisplayTools.createVisualizationComponent(criterion, container,
"Performance Criterion", false);
JScrollPane criterionPane = new ExtendedJScrollPane(component);
criterionPane.setBorder(null);
criterionPane.setBackground(Colors.WHITE);
mainPanel.add(criterionPane, criterion.getName());
}
if (criteriaNameList.isEmpty()) {
remove(mainPanel);
add(new ResourceLabel("result_view.no_criterions"));
return;
}
String[] criteriaNames = new String[criteriaNameList.size()];
criteriaNameList.toArray(criteriaNames);
// selection list
final JList<String> criteriaList = new MenuShortcutJList<String>(criteriaNames, false) {
private static final long serialVersionUID = 3031125186920370793L;
@Override
public Dimension getPreferredSize() {
Dimension dim = super.getPreferredSize();
dim.width = Math.max(150, dim.width);
return dim;
}
};
criteriaList.setCellRenderer(new CriterionListCellRenderer());
criteriaList.setOpaque(false);
criteriaList.setBorder(BorderFactory.createTitledBorder("Criterion"));
criteriaList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
criteriaList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
String selected = criteriaList.getSelectedValue();
cardLayout.show(mainPanel, selected);
}
});
JScrollPane listScrollPane = new ExtendedJScrollPane(criteriaList);
listScrollPane.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 2));
add(listScrollPane, BorderLayout.WEST);
// select first criterion
criteriaList.setSelectedIndices(new int[] { 0 });
}
private JComponent buildList() {
Application[] elements = new Application[] {
new Application("Address Book", "x-office-address-book.png"),
new Application("Calendar", "x-office-calendar.png"),
new Application("Presentation", "x-office-presentation.png"),
new Application("Spreadsheet", "x-office-spreadsheet.png"),
};
list = new JList(elements);
list.setCellRenderer(new ApplicationListCellRenderer());
list.setLayoutOrientation(JList.HORIZONTAL_WRAP);
list.setVisibleRowCount(2);
list.setBorder(BorderFactory.createEtchedBorder());
list.addMouseListener(new MouseAdapter() {
public void mouseClicked(MouseEvent e) {
if (e.getClickCount() == 2) {
int index = list.getSelectedIndex();
Rectangle bounds = list.getCellBounds(index, index);
Point location = new Point(bounds.x, bounds.y);
location = SwingUtilities.convertPoint(list, location, glassPane);
location.y -= 13;
bounds.setLocation(location);
glassPane.showSpring(bounds,
((Application) list.getSelectedValue()).icon.getImage());
}
}
});
JPanel panel = new JPanel(new GridBagLayout());
panel.add(new JLabel("Launcher"),
new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
panel.add(list, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0,
GridBagConstraints.CENTER, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
panel.add(new JLabel("Double-click an icon to launch the program"),
new GridBagConstraints(0, 2, 1, 1, 1.0, 1.0,
GridBagConstraints.LINE_START, GridBagConstraints.NONE,
new Insets(0, 0, 0, 0), 0, 0));
return panel;
}
public DateIntervalListEditor(final DateIntervalModel intervalsModel) {
super(new BorderLayout());
myIntervalsModel = intervalsModel;
myStart = new DefaultDateOption("generic.startDate") {
@Override
public void setValue(Date value) {
super.setValue(value);
if (intervalsModel.getMaxIntervalLength() == 1) {
DateIntervalListEditor.this.myFinish.setValue(value);
}
DateIntervalListEditor.this.updateActions();
}
};
myFinish = new DefaultDateOption("generic.endDate") {
@Override
public void setValue(Date value) {
super.setValue(value);
DateIntervalListEditor.this.updateActions();
}
};
myAddAction = new GPAction("add") {
@Override
public void actionPerformed(ActionEvent e) {
myIntervalsModel.add(DateInterval.createFromVisibleDates(myStart.getValue(), myFinish.getValue()));
myListModel.update();
}
};
myDeleteAction = new GPAction("delete") {
@Override
public void actionPerformed(ActionEvent e) {
int selected = myListSelectionModel.getMinSelectionIndex();
myIntervalsModel.remove(myIntervalsModel.getIntervals()[selected]);
myListModel.update();
myListSelectionModel.removeIndexInterval(selected, selected);
updateActions();
}
};
JPanel topPanel = new JPanel(new BorderLayout());
OptionsPageBuilder builder = new OptionsPageBuilder();
builder.setOptionKeyPrefix("");
GPOptionGroup group = myIntervalsModel.getMaxIntervalLength() == 1 ? new GPOptionGroup("",
new GPOption[] { myStart }) : new GPOptionGroup("", new GPOption[] { myStart, myFinish });
group.setTitled(false);
JComponent datesBox = builder.buildPlanePage(new GPOptionGroup[] { group });
topPanel.add(datesBox, BorderLayout.CENTER);
Box buttonBox = Box.createHorizontalBox();
buttonBox.setBorder(BorderFactory.createEmptyBorder(3, 0, 3, 0));
buttonBox.add(new JButton(myAddAction));
buttonBox.add(Box.createHorizontalStrut(5));
buttonBox.add(new JButton(myDeleteAction));
topPanel.add(buttonBox, BorderLayout.SOUTH);
topPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5));
add(topPanel, BorderLayout.NORTH);
JList list = new JList(myListModel);
list.setName("list");
list.setBorder(BorderFactory.createLoweredBevelBorder());
myListSelectionModel = list.getSelectionModel();
myListSelectionModel.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
updateActions();
}
});
JScrollPane scrollPane = new JScrollPane(list);
scrollPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
scrollPane.setPreferredSize(new Dimension(120, 200));
add(scrollPane, BorderLayout.CENTER);
updateActions();
}
public LicenseWindow() {
super("Licenses");
setIconImage(Amidst.icon);
licenseText.setEditable(false);
licenseText.setLineWrap(true);
licenseText.setWrapStyleWord(true);
licenses.add(new License("AMIDST", "licenses/amidst.txt"));
licenses.add(new License("Args4j", "licenses/args4j.txt"));
licenses.add(new License("Gson", "licenses/gson.txt"));
licenses.add(new License("JGoogleAnalytics", "licenses/jgoogleanalytics.txt"));
licenses.add(new License("JNBT", "licenses/jnbt.txt"));
licenses.add(new License("Kryonet", "licenses/kryonet.txt"));
licenses.add(new License("MiG Layout", "licenses/miglayout.txt"));
licenses.add(new License("Rhino", "licenses/rhino.txt"));
licenseList = new JList(licenses.toArray());
licenseList.setBorder(new LineBorder(Color.darkGray, 1));
Container contentPane = this.getContentPane();
MigLayout layout = new MigLayout();
contentPane.setLayout(layout);
contentPane.add(licenseList, "w 100!, h 0:2400:2400");
JScrollPane scrollPane = new JScrollPane(licenseText);
scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
contentPane.add(scrollPane, "w 0:4800:4800, h 0:2400:2400");
setSize(870, 550);
setVisible(true);
licenseList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
licenseList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
License license = (License)licenseList.getSelectedValue();
license.load();
if (license.isLoaded()) {
licenseText.setText(license.getContents());
licenseText.setCaretPosition(0);
}
}
});
licenseList.setSelectedIndex(0);
}
/**
* Instantiates a new list selector.
*
* @param listData the list data
*/
public ListSelector(Object[] listData) {
for (int i = 0; i < listData.length; i++)
listModel.addElement(listData[i]);
setLayout(new BorderLayout(4, 4));
list = new JList(listModel);
list.setFixedCellWidth(200);
list.setVisibleRowCount(3);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Border etchedBorder = BorderFactory.createEtchedBorder();
list.setBorder(etchedBorder);
JScrollPane scrollPane = new JScrollPane(list, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
add(scrollPane, BorderLayout.CENTER);
JPanel controlPanel = new JPanel();
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
gbc.insets = new Insets(2, 2, 2, 2);
controlPanel.setLayout(gbl);
addField = new JTextField(6);
addField.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.anchor = GridBagConstraints.NORTHEAST;
controlPanel.add(addField, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.NORTHWEST;
addButton = new SmallButton("Add");
addButton.addActionListener(this);
controlPanel.add(addButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
gbc.anchor = GridBagConstraints.WEST;
JPanel movePanel = new JPanel();
movePanel.setLayout(new GridLayout(1, 2, 4, 4));
moveUpButton = new ImageButton(Images.UP);
moveUpButton.addActionListener(this);
movePanel.add(moveUpButton);
moveDownButton = new ImageButton(Images.DOWN);
moveDownButton.addActionListener(this);
movePanel.add(moveDownButton);
controlPanel.add(movePanel, gbc);
gbc.gridx = 1;
gbc.anchor = GridBagConstraints.WEST;
gbc.anchor = GridBagConstraints.WEST;
removeButton = new SmallButton("Remove");
removeButton.addActionListener(this);
controlPanel.add(removeButton, gbc);
add(controlPanel, BorderLayout.EAST);
}