本文整理汇总了Java中javax.swing.ListSelectionModel类的典型用法代码示例。如果您正苦于以下问题:Java ListSelectionModel类的具体用法?Java ListSelectionModel怎么用?Java ListSelectionModel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ListSelectionModel类属于javax.swing包,在下文中一共展示了ListSelectionModel类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setSelectionInterval
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public void setSelectionInterval(int index0, int index1) {
clearSelection();
if (selectionMode == ListSelectionModel.SINGLE_SELECTION) {
modifySelectionInterval(index0, index1, true);
} else {
modifySelectionInterval(index1, index1, true);
}
fireValueChanged();
}
示例2: JCheckBoxList
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public JCheckBoxList() {
setCellRenderer(new CellRenderer());
addMouseListener(new MouseAdapter() {
@Override
public void mousePressed(MouseEvent e) {
int index = locationToIndex(e.getPoint());
if (index != -1) {
JCheckBox checkbox = getModel().getElementAt(index);
if (e.getPoint().x < checkbox.getHorizontalTextPosition()) {
checkbox.setSelected(!checkbox.isSelected());
}
repaint();
}
}
});
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
}
示例3: QubitTable
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public QubitTable(final int row_height) {
setFont(new Font("Tahoma", Font.PLAIN, 12));
setRowHeight(row_height);
setFocusable(false);
setRowSelectionAllowed(false);
setShowGrid(false);
setIntercellSpacing(new Dimension(0, 0));
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
setTableHeader(null);
setModel(new DefaultTableModel(new Object[][] {{"|0>"}}, new String[] {""}));
update_col_width();
qubits = "0";
}
示例4: getComponent
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public JComponent getComponent() {
if (panel == null) {
final ListView view = new ListView();
view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
class Panel extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
// Make sure action context works correctly:
{
setLayout(new BorderLayout());
add(view, BorderLayout.CENTER);
}
public ExplorerManager getExplorerManager() {
return manager;
}
@Override
public boolean requestFocusInWindow() {
return view.requestFocusInWindow();
}
public Lookup getLookup() {
return lookup;
}
}
panel = new Panel();
}
return panel;
}
示例5: buildTablePanel
import javax.swing.ListSelectionModel; //导入依赖的package包/类
private JScrollPane buildTablePanel() {
table = new JTable(new AddressBookTableModel(),new DefaultTableColumnModel());
TableColumn nameColumn = new TableColumn(0);
TableColumn addressColumn = new TableColumn(1);
table.addColumn(nameColumn);
table.addColumn(addressColumn);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // one at a time
table.getSelectionModel().addListSelectionListener(new AddressListSelectionListener());
table.addMouseListener(new AddressMouseListener());
// TODO: isolate in utility
TableCellRenderer renderer = table.getCellRenderer(0, 0);
Component comp = renderer.getTableCellRendererComponent(table, "123", false, false, 0, 0);
table.setRowHeight(new Double(comp.getPreferredSize().getHeight()).intValue() + 2);
JScrollPane scrollPane = new JScrollPane(table);
return scrollPane;
}
示例6: storeToXML
import javax.swing.ListSelectionModel; //导入依赖的package包/类
@Override
public Node storeToXML(Document doc) {
Object value = getValue();
int selectionMode = -1;
Object[] values = getEnumerationValues();
if (values[4].equals(value)) {
selectionMode = ListSelectionModel.SINGLE_SELECTION;
} else if (values[7].equals(value)) {
selectionMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION;
} else if (values[10].equals(value)) {
selectionMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION;
}
org.w3c.dom.Element el = null;
el = doc.createElement(XML_TABLE_SELECTION_MODEL);
el.setAttribute(ATTR_SELECTION_MODE, Integer.toString(selectionMode));
return el;
}
示例7: copyAnchorToSelection
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public void copyAnchorToSelection() {
if ((getSelectedRowCount() == 0) && (getSelectedColumnCount() == 0)) {
return;
}
if (dataModel instanceof ExactTableModel) {
stopEditing();
int rowFrom = selectionModel.getMinSelectionIndex();
int rowTo = selectionModel.getMaxSelectionIndex();
ListSelectionModel csm = columnModel.getSelectionModel();
int colFrom = csm.getMinSelectionIndex();
int colTo = csm.getMaxSelectionIndex();
int anchorRow = selectionModel.getAnchorSelectionIndex();
int anchorCol = csm.getAnchorSelectionIndex();
((ExactTableModel) dataModel).copyCellToArea(anchorRow, anchorCol, rowFrom, rowTo, colFrom, colTo);
updateRows(rowFrom, rowTo);
requestFocus();
}
}
示例8: makeList
import javax.swing.ListSelectionModel; //导入依赖的package包/类
private JList<String> makeList(final String[][] items, int visibleRows, Container parent) {
JList<String> list = new JList<>(new AbstractListModel<String>() {
/**
*
*/
private static final long serialVersionUID = 6510576197401709714L;
public String getElementAt(int i) {
return items[i][0];
}
public int getSize() {
return items.length;
}
});
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setVisibleRowCount(visibleRows);
parent.add(new JScrollPane(list));
return list;
}
示例9: run
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public void run() {
boolean multisel = (list.getSelectionMode() != ListSelectionModel.SINGLE_SELECTION);
int i = (multisel ? list.getLeadSelectionIndex() : list.getSelectedIndex());
if (i < 0) {
return;
}
Point p = list.indexToLocation(i);
if (p == null) {
return;
}
createPopup(p.x, p.y, false);
}
示例10: isSelectionModeBroken
import javax.swing.ListSelectionModel; //导入依赖的package包/类
/**
* Check if selection of the nodes could break
* the selection mode set in the ListSelectionModel.
* @param nodes the nodes for selection
* @return true if the selection mode is broken
*/
private boolean isSelectionModeBroken(Node[] nodes) {
// if nodes are empty or single then everthing is ok
// or if discontiguous selection then everthing ok
if (nodes.length <= 1 || outline.getSelectionModel().getSelectionMode() ==
ListSelectionModel.MULTIPLE_INTERVAL_SELECTION) {
return false;
}
// if many nodes
// breaks single selection mode
if (outline.getSelectionModel().getSelectionMode() ==
ListSelectionModel.SINGLE_SELECTION) {
return true;
}
// check the contiguous selection mode
// check selection's rows
// all is ok
return false;
}
示例11: CategoryList
import javax.swing.ListSelectionModel; //导入依赖的package包/类
/**
* Constructor.
*/
CategoryList( Category category, PalettePanel palettePanel ) {
this.category = category;
this.palettePanel = palettePanel;
if( isGTK || isNimbus ) {
setBackground( new Color( UIManager.getColor("Tree.background").getRGB() ) );//NOI18N
setOpaque(true);
} else {
if( "Aqua".equals(UIManager.getLookAndFeel().getID()) )
setBackground(UIManager.getColor("NbExplorerView.background"));
else
setBackground(UIManager.getColor ("Panel.background"));
}
setBorder (new EmptyBorder (0, 0, 0, 0));
setVisibleRowCount (0);
setSelectionMode (ListSelectionModel.SINGLE_SELECTION);
setCellRenderer (getItemRenderer ());
setLayoutOrientation( HORIZONTAL_WRAP );
getAccessibleContext().setAccessibleName( category.getDisplayName() );
getAccessibleContext().setAccessibleDescription( category.getShortDescription() );
initActions();
}
示例12: initList
import javax.swing.ListSelectionModel; //导入依赖的package包/类
@NbBundle.Messages({
"MSG_Detecting_Wait=Detecting installations, please wait..."
})
private void initList() {
installationList.setListData(new Object[]{
Bundle.MSG_Detecting_Wait()
});
installationList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
installationList.setEnabled(false);
RequestProcessor.getDefault().post(new Runnable() {
@Override
public void run() {
final List<Installation> installations =
InstallationManager.detectAllInstallations();
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
updateListForDetectedInstallations(installations);
}
});
}
});
}
示例13: selectRows
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public void selectRows() throws Throwable {
final JTable table = (JTable) ComponentUtils.findComponent(JTable.class, frame);
final LoggingRecorder lr = new LoggingRecorder();
siw(new Runnable() {
@Override public void run() {
table.setRowSelectionAllowed(true);
table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
table.addRowSelectionInterval(1, 1);
table.addRowSelectionInterval(3, 3);
table.addColumnSelectionInterval(0, 0);
RTable rTable = new RTable(table, null, null, lr);
rTable.focusLost(null);
}
});
Call call = lr.getCall();
AssertJUnit.assertEquals("select", call.getFunction());
AssertJUnit.assertEquals("rows:[1,3],columns:[First Name]", call.getState());
}
示例14: PluginDialog
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public PluginDialog()
{
listModel = new DefaultListModel();
list = new JList();
list.setModel(listModel);
list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
for( String name : plugins.keySet() )
{
listModel.addElement(name);
}
setLayout(new BorderLayout());
add(new JScrollPane(list));
}
示例15: getComponent
import javax.swing.ListSelectionModel; //导入依赖的package包/类
public JComponent getComponent() {
if (panel == null) {
final BeanTreeView view = new BeanTreeView();
view.setRootVisible(false);
view.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
class Panel extends JPanel implements ExplorerManager.Provider, Lookup.Provider {
// Make sure action context works correctly:
private final Lookup lookup = ExplorerUtils.createLookup(manager, new ActionMap());
{
setLayout(new BorderLayout());
add(view, BorderLayout.CENTER);
}
public ExplorerManager getExplorerManager() {
return manager;
}
public Lookup getLookup() {
return lookup;
}
}
panel = new Panel();
}
return panel;
}