下面列出了javax.swing.DefaultListSelectionModel#addListSelectionListener ( ) 实例代码,或者点击链接到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 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);
}
TaskModel(Executor eventExecutor) {
selectionModel = new DefaultListSelectionModel();
model = new DefaultListModel<>();
dataListeners = new LinkedHashSet<ListDataListener>();
selectionListeners = new LinkedHashSet<ListSelectionListener>();
TaskListener list = new TaskListener();
model.addListDataListener(list);
selectionModel.addListSelectionListener(list);
this.eventExecutor = eventExecutor;
}
public CheckBoxListDecorator(JList<T> list) {
this.list = list;
list.setCellRenderer(new CheckBoxListCellRenderer<T>());
list.addMouseListener(this);
list.addPropertyChangeListener(this);
list.registerKeyboardAction(this, KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), JComponent.WHEN_FOCUSED);
checkBoxSelectionModel = new DefaultListSelectionModel();
checkBoxSelectionModel.addListSelectionListener(this);
enabled = new HashMap<Integer, Boolean>();
width = new JCheckBox().getPreferredSize().width;
}
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));
}
/**
* Add a column to the end of the model.
*/
protected void addColumn() {
DefaultListSelectionModel newListModel = new DefaultListSelectionModel();
listSelectionModels.add(newListModel);
newListModel.addListSelectionListener(this);
}