下面列出了javax.swing.DefaultListSelectionModel#setSelectionMode ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private JScrollPane initTableComponent() {
table = new JTable();
// Adjust some visual appearence
table.setRowHeight(22);
table.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
// Add listeners
selectionModel = new DefaultListSelectionModel();
selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(rowSelectionListener);
table.setSelectionModel(selectionModel);
table.addMouseListener(listMouseListener);
initTableKeyListener();
// Envelope in scrollpane
scrollPane = new JScrollPane();
scrollPane.addMouseListener(listMouseListener);
scrollPane.setViewportView(table);
return scrollPane;
}
private JScrollPane initTableComponent() {
table = new JTable();
// Adjust some visual appearance
table.setRowHeight(22);
table.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
// Add listeners
selectionModel = new DefaultListSelectionModel();
selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener((evt) -> pm.setSelected(getSelectedRow()));
table.setSelectionModel(selectionModel);
table.addMouseListener(listMouseListener);
table.getActionMap().put("confirmRow", enterAction);
table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirmRow");
// Envelope in scrollpane
scrollPane = new JScrollPane();
scrollPane.setViewportView(table);
return scrollPane;
}
private JScrollPane initTableComponent() {
table = new JTable();
// Adjust some visual appearence
table.setRowHeight(22);
// Add listeners
selectionModel = new DefaultListSelectionModel();
selectionModel.setSelectionMode(DefaultListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(rowSelectionListener);
table.setSelectionModel(selectionModel);
table.addMouseListener(listMouseListener);
table.setDefaultRenderer(EncryptBackAction.class, new EncryptBackActionCellRenderer());
table.addMouseListener(encrBackClickHandler);
initTableKeyListener();
// Envelope in scrollpane
scrollPane = new JScrollPane();
scrollPane.addMouseListener(listMouseListener);
scrollPane.setViewportView(table);
return scrollPane;
}
public SorterTableColumnModel(Sortables[] columnHeaders) {
MainFrame mainFrame = MainFrame.getInstance();
int x = 0;
for (Sortables c : columnHeaders) {
if (!c.isAvailable(mainFrame)) {
continue;
}
shown.add(c);
TableColumn tc = makeTableColumn(x, c);
columnList.add(tc);
x++;
}
dlsm = new DefaultListSelectionModel();
dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
orderUpdate();
check();
}
public EndmemberFormModel(AppContext appContext) {
this.appContext = appContext;
endmemberListModel = new DefaultListModel<>();
endmemberListSelectionModel = new DefaultListSelectionModel();
endmemberListSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
endmemberListModel.addListDataListener(new EndmemberListDataListener());
endmemberListSelectionModel.addListSelectionListener(new EndmemberListSelectionListener());
addAction = new AddAction();
removeAction = new RemoveAction();
clearAction = new ClearAction();
exportAction = new ExportAction();
endmemberDiagram = new Diagram();
endmemberDiagram.setXAxis(new DiagramAxis("Wavelength", ""));
endmemberDiagram.setYAxis(new DiagramAxis("Radiation", ""));
endmemberDiagram.setDrawGrid(false);
propertyChangeSupport = new PropertyChangeSupport(this);
}
void createListModel()
{
list_model=new javax.swing.DefaultListModel();
list_online_clients = new javax.swing.JList(list_model);
list_online_clients.setBorder(javax.swing.BorderFactory.createTitledBorder("Buddy List"));
dlsm=new DefaultListSelectionModel();
dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list_online_clients.setSelectionModel(dlsm);
this.setLayout(new BorderLayout());
this.add(list_online_clients,BorderLayout.CENTER);
}
void createListModel()
{
list_model=new javax.swing.DefaultListModel();
list_online_clients = new javax.swing.JList(list_model);
list_online_clients.setBorder(javax.swing.BorderFactory.createTitledBorder("ONLINE CLIENTS"));
dlsm=new DefaultListSelectionModel();
dlsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list_online_clients.setSelectionModel(dlsm);
list_panel.setLayout(new BorderLayout());
list_panel.add(list_online_clients);
}
@Override
protected ListSelectionModel createListSelectionModel() {
DefaultListSelectionModel model = new DefaultListSelectionModel();
model.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
return model;
}
private static ListSelectionModel createListSelectionModel(int selectionMode) {
DefaultListSelectionModel model = new DefaultListSelectionModel();
model.setSelectionMode(selectionMode);
return model;
}
public PhotoList(ZooracleContentPanel zooracleContentPanel)
{
this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
this.zooracleContentPanel = zooracleContentPanel;
// Set the frame characteristics
// setSize(150, 600);
setBackground(Color.gray);
// Create a panel to hold all other components
topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.Y_AXIS));
this.add(topPanel);
// Create some data
// String dataValues[][] = { { "12", "234", "67" }, { "-123", "43", "853" }, { "93", "89.2", "109" }, { "279", "9033", "3092" } };
// Create a new table instance
table = new JTable(null, columnNames);
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
// table.setMinimumSize(new Dimension(150, 600));
// table.setPreferredSize(new Dimension(150, 600));
// table.setD
selectionModel = new DefaultListSelectionModel();
model = new DefaultTableModel();
// table.setC
selectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
selectionModel.addListSelectionListener(new ListSelectionListener()
{
public void valueChanged(ListSelectionEvent e)
{
int selectionIndex = table.getSelectedRow();
if (lastSelectionIndex != selectionIndex)
{
lastSelectionIndex = selectionIndex;
if (selectionIndex==-1)
return;
System.out.println(table.getValueAt(selectionIndex, 0));
System.out.println("sele:" + selectionIndex);
if (PhotoList.this.zooracleContentPanel instanceof ImportView)
{
((ImportView)(PhotoList.this.zooracleContentPanel)).setCurrentPhoto(selectionIndex);
}
// if (selectionIndex > 2)
// PhotoList.this.maximize(false);
}
}
});
// table.setDefaultRenderer(Object.class, new EditedCellRenderer(this));
table.setSelectionModel(selectionModel);
table.setDefaultRenderer(String.class, new BoardTableCellRenderer());
table.setDefaultRenderer(Object.class, new BoardTableCellRenderer());
table.setModel(model);
// table.setMaximumSize(new Dimension(100, 300));
// Add the table to a scrolling pane
scrollPane = new JScrollPane();
// scrollPane.add(table.getTableHeader());
// scrollPane.add(table);
// topPanel.add(scrollPane);
topPanel.add(table.getTableHeader());
topPanel.add(new JScrollPane(table));
}