List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION
int MULTIPLE_INTERVAL_SELECTION
To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.
Click Source Link
From source file:net.sf.vfsjfilechooser.accessories.bookmarks.BookmarksManagerPanel.java
public BookmarksManagerPanel(BookmarksDialog parentDialog, VFSJFileChooser chooser) { this.parentDialog = parentDialog; this.chooser = chooser; model = new Bookmarks(); table = new JTable(model); scrollPane = new JScrollPane(table); table.setPreferredScrollableViewportSize(tableSize); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); bCancel = new JButton(VFSResources.getMessage("VFSJFileChooser.closeButtonText")); bOpen = new JButton(VFSResources.getMessage("VFSJFileChooser.openButtonText")); bOpen.setIcon(/*w ww. j a va2s. c o m*/ new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/document-open.png"))); bOpen.setHorizontalAlignment(SwingConstants.LEFT); bAdd = new JButton(VFSResources.getMessage("VFSJFileChooser.addButtonText")); bAdd.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/list-add.png"))); bAdd.setHorizontalAlignment(SwingConstants.LEFT); bEdit = new JButton(VFSResources.getMessage("VFSJFileChooser.editButtonText")); bEdit.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/book_edit.png"))); bEdit.setHorizontalAlignment(SwingConstants.LEFT); bDelete = new JButton(VFSResources.getMessage("VFSJFileChooser.deleteButtonText")); bDelete.setIcon( new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/list-remove.png"))); bDelete.setHorizontalAlignment(SwingConstants.LEFT); bMoveUp = new JButton(VFSResources.getMessage("VFSJFileChooser.moveUpButtonText")); bMoveUp.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/go-up.png"))); bMoveUp.setHorizontalAlignment(SwingConstants.LEFT); bMoveDown = new JButton(VFSResources.getMessage("VFSJFileChooser.moveDownButtonText")); bMoveDown.setIcon(new ImageIcon(getClass().getResource("/net/sf/vfsjfilechooser/plaf/icons/go-down.png"))); bMoveDown.setHorizontalAlignment(SwingConstants.LEFT); final ActionHandler ah = new ActionHandler(); bOpen.addActionListener(ah); bCancel.addActionListener(ah); bEdit.addActionListener(ah); bAdd.addActionListener(ah); bDelete.addActionListener(ah); bMoveUp.addActionListener(ah); bMoveDown.addActionListener(ah); final Box south = Box.createHorizontalBox(); south.add(Box.createHorizontalGlue()); south.add(bCancel); south.add(Box.createHorizontalGlue()); final JPanel buttons = new JPanel(new GridLayout(0, 1, 5, 5)); buttons.add(bAdd); buttons.add(bEdit); buttons.add(bDelete); buttons.add(bOpen); buttons.add(Box.createVerticalStrut(10)); buttons.add(bMoveUp); buttons.add(bMoveDown); JPanel east = new JPanel(); east.add(buttons, BorderLayout.NORTH); east.add(new JPanel(), BorderLayout.CENTER); // don't ask setLayout(new BorderLayout(10, 10)); add(scrollPane, BorderLayout.CENTER); add(south, BorderLayout.SOUTH); add(east, BorderLayout.EAST); setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, UIManager.getColor("Panel.background"))); }
From source file:com.mirth.connect.client.ui.alert.AlertChannelPane.java
private void makeChannelTable() { ChannelTreeTableModel model = new ChannelTreeTableModel(); model.setColumnIdentifiers(Arrays.asList(new String[] { "test" })); channelTreeTable.setTreeTableModel(model); channelTreeTable.setDoubleBuffered(true); channelTreeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); channelTreeTable.setHorizontalScrollEnabled(true); channelTreeTable.packTable(UIConstants.COL_MARGIN); channelTreeTable.setRowHeight(UIConstants.ROW_HEIGHT); channelTreeTable.setOpaque(true);//from w w w. j ava 2s . c o m channelTreeTable.setRowSelectionAllowed(true); channelTreeTable.putClientProperty("JTree.lineStyle", "Horizontal"); channelTreeTable.setAutoCreateColumnsFromModel(false); channelTreeTable.setShowGrid(true, true); channelTreeTable.setTableHeader(null); channelTreeTable.setDragEnabled(false); channelTreeTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { boolean enabled = channelTreeTable.getSelectedRowCount() > 0; enableButton.setEnabled(enabled); disableButton.setEnabled(enabled); } } }); channelTreeTable.setTreeCellRenderer(new TreeCellRenderer() { private JLabel label = new JLabel(); @Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { if (value != null) { if (value instanceof ChannelTreeTableNode) { ChannelTreeTableNode channelNode = (ChannelTreeTableNode) value; ImageIcon icon; if (channelNode.getChildCount() == 0) { // node is a channel node with no children icon = channelNode.isEnabled() ? UIConstants.ICON_BULLET_GREEN : UIConstants.ICON_BULLET_RED; } else { // node is a channel node with children boolean hasDisabled = false; boolean hasEnabled = false; for (int i = 0; i < channelNode.getChildCount(); i++) { ConnectorTreeTableNode connectorNode = (ConnectorTreeTableNode) channelNode .getChildAt(i); if (connectorNode.isEnabled()) { hasEnabled = true; } else { hasDisabled = true; } } if (hasEnabled && hasDisabled) { icon = UIConstants.ICON_BULLET_YELLOW; } else if (hasDisabled) { icon = UIConstants.ICON_BULLET_RED; } else if (hasEnabled) { icon = UIConstants.ICON_BULLET_GREEN; } else { // This should never occur because a channel should never be a leaf. icon = UIConstants.ICON_BULLET_RED; } } label.setText(channelNode.getChannelName()); label.setIcon(icon); } else if (value instanceof ConnectorTreeTableNode) { ConnectorTreeTableNode connectorNode = (ConnectorTreeTableNode) value; ImageIcon icon = connectorNode.isEnabled() ? UIConstants.ICON_BULLET_GREEN : UIConstants.ICON_BULLET_RED; label.setText(connectorNode.getConnectorName()); label.setIcon(icon); } } return label; } }); channelTreeTable.expandAll(); }
From source file:com.googlecode.vfsjfilechooser2.accessories.bookmarks.BookmarksManagerPanel.java
public BookmarksManagerPanel(BookmarksDialog parentDialog, VFSJFileChooser chooser) { this.parentDialog = parentDialog; this.chooser = chooser; model = new Bookmarks(); table = new JTable(model); scrollPane = new JScrollPane(table); table.setPreferredScrollableViewportSize(tableSize); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); bCancel = new JButton(VFSResources.getMessage("VFSJFileChooser.closeButtonText")); bOpen = new JButton(VFSResources.getMessage("VFSJFileChooser.openButtonText")); bOpen.setIcon(new ImageIcon( getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/document-open.png"))); bOpen.setHorizontalAlignment(SwingConstants.LEFT); bAdd = new JButton(VFSResources.getMessage("VFSJFileChooser.addButtonText")); bAdd.setIcon(/*ww w . j a v a 2s .c o m*/ new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/list-add.png"))); bAdd.setHorizontalAlignment(SwingConstants.LEFT); bEdit = new JButton(VFSResources.getMessage("VFSJFileChooser.editButtonText")); bEdit.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/book_edit.png"))); bEdit.setHorizontalAlignment(SwingConstants.LEFT); bDelete = new JButton(VFSResources.getMessage("VFSJFileChooser.deleteButtonText")); bDelete.setIcon(new ImageIcon( getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/list-remove.png"))); bDelete.setHorizontalAlignment(SwingConstants.LEFT); bMoveUp = new JButton(VFSResources.getMessage("VFSJFileChooser.moveUpButtonText")); bMoveUp.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/go-up.png"))); bMoveUp.setHorizontalAlignment(SwingConstants.LEFT); bMoveDown = new JButton(VFSResources.getMessage("VFSJFileChooser.moveDownButtonText")); bMoveDown.setIcon( new ImageIcon(getClass().getResource("/com/googlecode/vfsjfilechooser2/plaf/icons/go-down.png"))); bMoveDown.setHorizontalAlignment(SwingConstants.LEFT); final ActionHandler ah = new ActionHandler(); bOpen.addActionListener(ah); bCancel.addActionListener(ah); bEdit.addActionListener(ah); bAdd.addActionListener(ah); bDelete.addActionListener(ah); bMoveUp.addActionListener(ah); bMoveDown.addActionListener(ah); final Box south = Box.createHorizontalBox(); south.add(Box.createHorizontalGlue()); south.add(bCancel); south.add(Box.createHorizontalGlue()); final JPanel buttons = new JPanel(new GridLayout(0, 1, 5, 5)); buttons.add(bAdd); buttons.add(bEdit); buttons.add(bDelete); buttons.add(bOpen); buttons.add(Box.createVerticalStrut(10)); buttons.add(bMoveUp); buttons.add(bMoveDown); JPanel east = new JPanel(); east.add(buttons, BorderLayout.NORTH); east.add(new JPanel(), BorderLayout.CENTER); // don't ask setLayout(new BorderLayout(10, 10)); add(scrollPane, BorderLayout.CENTER); add(south, BorderLayout.SOUTH); add(east, BorderLayout.EAST); setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, UIManager.getColor("Panel.background"))); }
From source file:events.ListSelectionDemo.java
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = { "one", "two", "three", "four", "five", "six", "seven" }; String[] columnNames = { "French", "Spanish", "Italian" }; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/* ww w . ja va 2s .c om*/ comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); //topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
From source file:be.ugent.maf.cellmissy.gui.controller.analysis.doseresponse.generic.GenericDRInputController.java
@Override public void initDRInputData() { List<DoseResponsePair> doseResponseData = doseResponseController.getImportedDRDataHolder() .getDoseResponseData();/* w ww . j ava 2 s . com*/ // create and set the table model for the top panel table using the loaded data setTableModel(createTableModel(doseResponseData)); //number of replicates per condition will be added to a list as information List<Integer> numberOfReplicates = getNumberOfReplicates(doseResponseData); // put conditions in selectable list ObservableList<DoseResponsePair> doseResponsePairBindingList = ObservableCollections .observableList(doseResponseData); JListBinding jListBinding = SwingBindings.createJListBinding(AutoBinding.UpdateStrategy.READ_WRITE, doseResponsePairBindingList, dRInputPanel.getConditionsList()); bindingGroup.addBinding(jListBinding); bindingGroup.bind(); dRInputPanel.getConditionsList() .setCellRenderer(new RectIconListRenderer(doseResponseData, numberOfReplicates)); dRInputPanel.getConditionsList().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); }
From source file:com.t3.client.ui.AddResourceDialog.java
public void initLibraryList() { JList list = getLibraryList(); list.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); list.setModel(new MessageListModel(I18N.getText("dialog.addresource.downloading"))); }
From source file:events.TableListSelectionDemo.java
public TableListSelectionDemo() { super(new BorderLayout()); String[] columnNames = { "French", "Spanish", "Italian" }; String[][] tableData = { { "un", "uno", "uno" }, { "deux", "dos", "due" }, { "trois", "tres", "tre" }, { "quatre", "cuatro", "quattro" }, { "cinq", "cinco", "cinque" }, { "six", "seis", "sei" }, { "sept", "siete", "sette" } }; table = new JTable(tableData, columnNames); listSelectionModel = table.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); table.setSelectionModel(listSelectionModel); JScrollPane tablePane = new JScrollPane(table); //Build control area (use default FlowLayout). JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/*from ww w. j a v a2s. com*/ comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); //Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); //Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); JPanel tableContainer = new JPanel(new GridLayout(1, 1)); tableContainer.setBorder(BorderFactory.createTitledBorder("Table")); tableContainer.add(tablePane); tablePane.setPreferredSize(new Dimension(420, 130)); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(250, 50)); topHalf.setPreferredSize(new Dimension(200, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); //XXX: next line needed if bottomHalf is a scroll pane: //bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 110)); splitPane.add(bottomHalf); }
From source file:FillViewportHeightDemo.java
public FillViewportHeightDemo() { super("Empty Table DnD Demo"); tableModel = getDefaultTableModel(); table = new JTable(tableModel); table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); table.setDropMode(DropMode.INSERT_ROWS); table.setTransferHandler(new TransferHandler() { public boolean canImport(TransferSupport support) { // for the demo, we'll only support drops (not clipboard paste) if (!support.isDrop()) { return false; }/* w w w . j av a 2 s. co m*/ // we only import Strings if (!support.isDataFlavorSupported(DataFlavor.stringFlavor)) { return false; } return true; } public boolean importData(TransferSupport support) { // if we can't handle the import, say so if (!canImport(support)) { return false; } // fetch the drop location JTable.DropLocation dl = (JTable.DropLocation) support.getDropLocation(); int row = dl.getRow(); // fetch the data and bail if this fails String data; try { data = (String) support.getTransferable().getTransferData(DataFlavor.stringFlavor); } catch (UnsupportedFlavorException e) { return false; } catch (IOException e) { return false; } String[] rowData = data.split(","); tableModel.insertRow(row, rowData); Rectangle rect = table.getCellRect(row, 0, false); if (rect != null) { table.scrollRectToVisible(rect); } // demo stuff - remove for blog model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); // end demo stuff return true; } }); JList dragFrom = new JList(model); dragFrom.setFocusable(false); dragFrom.setPrototypeCellValue(getNextString(100)); model.insertElementAt(getNextString(count++), 0); dragFrom.setDragEnabled(true); dragFrom.setBorder(BorderFactory.createLoweredBevelBorder()); dragFrom.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent me) { if (SwingUtilities.isLeftMouseButton(me) && me.getClickCount() % 2 == 0) { String text = (String) model.getElementAt(0); String[] rowData = text.split(","); tableModel.insertRow(table.getRowCount(), rowData); model.removeAllElements(); model.insertElementAt(getNextString(count++), 0); } } }); JPanel p = new JPanel(); p.setLayout(new BoxLayout(p, BoxLayout.X_AXIS)); JPanel wrap = new JPanel(); wrap.add(new JLabel("Drag from here:")); wrap.add(dragFrom); p.add(Box.createHorizontalStrut(4)); p.add(Box.createGlue()); p.add(wrap); p.add(Box.createGlue()); p.add(Box.createHorizontalStrut(4)); getContentPane().add(p, BorderLayout.NORTH); JScrollPane sp = new JScrollPane(table); getContentPane().add(sp, BorderLayout.CENTER); fillBox = new JCheckBoxMenuItem("Fill Viewport Height"); fillBox.addActionListener(this); JMenuBar mb = new JMenuBar(); JMenu options = new JMenu("Options"); mb.add(options); setJMenuBar(mb); JMenuItem clear = new JMenuItem("Reset"); clear.addActionListener(this); options.add(clear); options.add(fillBox); getContentPane().setPreferredSize(new Dimension(260, 180)); }
From source file:ListSelectionDemo.java
public ListSelectionDemo() { super(new BorderLayout()); String[] listData = { "one", "two", "three", "four", "five", "six", "seven" }; String[] columnNames = { "French", "Spanish", "Italian" }; list = new JList(listData); listSelectionModel = list.getSelectionModel(); listSelectionModel.addListSelectionListener(new SharedListSelectionHandler()); JScrollPane listPane = new JScrollPane(list); JPanel controlPane = new JPanel(); String[] modes = { "SINGLE_SELECTION", "SINGLE_INTERVAL_SELECTION", "MULTIPLE_INTERVAL_SELECTION" }; final JComboBox comboBox = new JComboBox(modes); comboBox.setSelectedIndex(2);/* w w w . ja v a 2 s . c o m*/ comboBox.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newMode = (String) comboBox.getSelectedItem(); if (newMode.equals("SINGLE_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); } else if (newMode.equals("SINGLE_INTERVAL_SELECTION")) { listSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); } else { listSelectionModel.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); } output.append("----------" + "Mode: " + newMode + "----------" + newline); } }); controlPane.add(new JLabel("Selection mode:")); controlPane.add(comboBox); // Build output area. output = new JTextArea(1, 10); output.setEditable(false); JScrollPane outputPane = new JScrollPane(output, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED); // Do the layout. JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT); add(splitPane, BorderLayout.CENTER); JPanel topHalf = new JPanel(); topHalf.setLayout(new BoxLayout(topHalf, BoxLayout.LINE_AXIS)); JPanel listContainer = new JPanel(new GridLayout(1, 1)); listContainer.setBorder(BorderFactory.createTitledBorder("List")); listContainer.add(listPane); topHalf.setBorder(BorderFactory.createEmptyBorder(5, 5, 0, 5)); topHalf.add(listContainer); // topHalf.add(tableContainer); topHalf.setMinimumSize(new Dimension(100, 50)); topHalf.setPreferredSize(new Dimension(100, 110)); splitPane.add(topHalf); JPanel bottomHalf = new JPanel(new BorderLayout()); bottomHalf.add(controlPane, BorderLayout.PAGE_START); bottomHalf.add(outputPane, BorderLayout.CENTER); // XXX: next line needed if bottomHalf is a scroll pane: // bottomHalf.setMinimumSize(new Dimension(400, 50)); bottomHalf.setPreferredSize(new Dimension(450, 135)); splitPane.add(bottomHalf); }
From source file:TableIt.java
public TableIt() { JFrame f = new JFrame(); TableModel tm = new MyTableModel(); final JTable table = new JTable(tm); TableColumnModel tcm = table.getColumnModel(); TableColumn column = tcm.getColumn(tcm.getColumnCount() - 1); TableCellRenderer renderer = new MyTableCellRenderer(); column.setCellRenderer(renderer);/* w ww .j av a 2s .co m*/ JButton selectionType = new JButton("Next Type"); selectionType.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { boolean rowSet = table.getRowSelectionAllowed(); boolean colSet = table.getColumnSelectionAllowed(); boolean cellSet = table.getCellSelectionEnabled(); boolean setRow = !rowSet; boolean setCol = rowSet ^ colSet; boolean setCell = rowSet & colSet; table.setCellSelectionEnabled(setCell); table.setColumnSelectionAllowed(setCol); table.setRowSelectionAllowed(setRow); System.out.println("Row Selection Allowed? " + setRow); System.out.println("Column Selection Allowed? " + setCol); System.out.println("Cell Selection Enabled? " + setCell); table.repaint(); } }); JButton selectionMode = new JButton("Next Mode"); selectionMode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { ListSelectionModel lsm = table.getSelectionModel(); int mode = lsm.getSelectionMode(); int nextMode; String nextModeString; if (mode == ListSelectionModel.SINGLE_SELECTION) { nextMode = ListSelectionModel.SINGLE_INTERVAL_SELECTION; nextModeString = "Single Interval Selection"; } else if (mode == ListSelectionModel.SINGLE_INTERVAL_SELECTION) { nextMode = ListSelectionModel.MULTIPLE_INTERVAL_SELECTION; nextModeString = "Multiple Interval Selection"; } else { nextMode = ListSelectionModel.SINGLE_SELECTION; nextModeString = "Single Selection"; } lsm.setSelectionMode(nextMode); System.out.println("Selection Mode: " + nextModeString); table.repaint(); } }); JPanel jp = new JPanel(); jp.add(selectionType); jp.add(selectionMode); JScrollPane jsp = new JScrollPane(table); Container c = f.getContentPane(); c.add(jsp, BorderLayout.CENTER); c.add(jp, BorderLayout.SOUTH); f.setSize(300, 250); f.show(); }