Java Code Examples for javax.swing.DefaultListSelectionModel#addListSelectionListener()

The following examples show how to use javax.swing.DefaultListSelectionModel#addListSelectionListener() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: KeysTableView.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: HistoryQuickSearchView.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 3
Source File: MainFrameView.java    From pgptool with GNU General Public License v3.0 6 votes vote down vote up
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;
}
 
Example 4
Source File: EndmemberFormModel.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
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);
}
 
Example 5
Source File: TaskModel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 6
Source File: CheckBoxListDecorator.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: PhotoList.java    From mvisc with GNU General Public License v3.0 4 votes vote down vote up
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));
	}
 
Example 8
Source File: TableSelectionModel.java    From wandora with GNU General Public License v3.0 4 votes vote down vote up
/**
* Add a column to the end of the model.
*/
protected void addColumn() {
    DefaultListSelectionModel newListModel = new DefaultListSelectionModel();
    listSelectionModels.add(newListModel);
    newListModel.addListSelectionListener(this);
}