Java Code Examples for javax.swing.JTable#setColumnSelectionAllowed()
The following examples show how to use
javax.swing.JTable#setColumnSelectionAllowed() .
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: TableSorter.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 2
Source File: TableSorter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 3
Source File: TableSorter.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); final MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { final TableColumnModel columnModel = tableView.getColumnModel(); final int viewColumn = columnModel.getColumnIndexAtX(e.getX()); final int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //System.out.println("Sorting ..."); final int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; final boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; final JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 4
Source File: TableSorter.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); final MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { final TableColumnModel columnModel = tableView.getColumnModel(); final int viewColumn = columnModel.getColumnIndexAtX(e.getX()); final int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { //System.out.println("Sorting ..."); final int shiftPressed = e.getModifiers()&InputEvent.SHIFT_MASK; final boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; final JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 5
Source File: TableSorter.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 6
Source File: TableSorter.java From openjdk-8 with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 7
Source File: TableSorter.java From openjdk-8-source with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 8
Source File: TableSorter.java From jdk8u-jdk with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 9
Source File: TableSorter.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 10
Source File: TableSorter.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 11
Source File: TableSorter.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { System.out.println("Sorting ..."); int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; boolean ascending = (shiftPressed == 0); sorter.sortByColumn(column, ascending); } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 12
Source File: TableSorter.java From groovy with Apache License 2.0 | 6 votes |
public void addMouseListenerToHeaderInTable(JTable table) { final TableSorter sorter = this; final JTable tableView = table; tableView.setColumnSelectionAllowed(false); MouseAdapter listMouseListener = new MouseAdapter() { public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = tableView.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = tableView.convertColumnIndexToModel(viewColumn); if (e.getClickCount() == 1 && column != -1) { if (lastSortedColumn == column) ascending = !ascending; sorter.sortByColumn(column, ascending); lastSortedColumn = column; } } }; JTableHeader th = tableView.getTableHeader(); th.addMouseListener(listMouseListener); }
Example 13
Source File: MaianaImportPanel.java From wandora with GNU General Public License v3.0 | 5 votes |
public void setTopicMapsList() { if(getApiKey() != null) { try { JSONObject list = MaianaUtils.listAvailableTopicMaps(getApiEndPoint(), getApiKey()); if(list.has("msg")) { WandoraOptionPane.showMessageDialog(window, list.getString("msg"), "API says", WandoraOptionPane.WARNING_MESSAGE); //System.out.println("REPLY:"+list.toString()); } if(list.has("data")) { mapTable = new JTable(); mapTable.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); if(list != null) { JSONArray datas = list.getJSONArray("data"); TopicMapsTableModel myModel = new TopicMapsTableModel(datas); mapTable.setModel(myModel); mapTable.setRowSorter(new TableRowSorter(myModel)); mapTable.setColumnSelectionAllowed(false); mapTable.setRowSelectionAllowed(true); mapTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); TableColumn column = null; for (int i=0; i < mapTable.getColumnCount(); i++) { column = mapTable.getColumnModel().getColumn(i); column.setPreferredWidth(myModel.getColumnWidth(i)); } tableScrollPane.setViewportView(mapTable); } } } catch(Exception e) { Wandora.getWandora().displayException("Exception '"+e.getMessage()+"' occurred while getting the list of topic maps.", e); } } }
Example 14
Source File: VariationPerParameterTableController.java From OpenDA with GNU Lesser General Public License v3.0 | 5 votes |
/** * setting up the table. * * @param table JTable to store this.correlationTableModel */ private void setupBasicTableProperties(JTable table) { table.clearSelection(); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); TableRenderer cellRenderer = new TableRenderer(new JTextField()); table.setRowSelectionAllowed(true); table.setColumnSelectionAllowed(false); table.setVisible(true); table.setModel(this.variationPerParameterTableModel); initColumnSizes(table); for (int i = 0; i < table.getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(cellRenderer); } TableColumn columnName = table.getColumnModel().getColumn(VariationPerParameterTableModel.COLUMN_NAME); columnName.setCellEditor(new TextCellEditor()); TableColumn columnBasicValue = table.getColumnModel().getColumn(VariationPerParameterTableModel.COLUMN_BASIC_VALUE); columnBasicValue.setCellEditor(new TextCellEditor()); setupVariationFunctionComboBoxColumn(); this.variationPerParameterTableModel.fireTableDataChanged(); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); //select first row. table.getSelectionModel().setSelectionInterval(0, 0); }
Example 15
Source File: SortableAndSearchableWrapperTableModel.java From meka with GNU General Public License v3.0 | 5 votes |
/** * Adds a mouselistener to the header: left-click on the header sorts in * ascending manner, using shift-left-click in descending manner. * * @param table the table to add the listener to */ public void addMouseListenerToHeader(JTable table) { final SortableAndSearchableWrapperTableModel fModel; final JTable fTable; JTableHeader header; fModel = this; fTable = table; fTable.setColumnSelectionAllowed(false); header = fTable.getTableHeader(); if (header != null) { if (m_MouseListener == null) { m_MouseListener = new MouseAdapter() { @Override public void mouseClicked(MouseEvent e) { TableColumnModel columnModel = fTable.getColumnModel(); int viewColumn = columnModel.getColumnIndexAtX(e.getX()); int column = fTable.convertColumnIndexToModel(viewColumn); if (MouseUtils.isLeftClick(e) && !e.isAltDown() && !e.isControlDown() && (column != -1)) fModel.sort(column, !e.isShiftDown()); } }; } header.addMouseListener(m_MouseListener); } }
Example 16
Source File: LanguageTableModel.java From pcgen with GNU Lesser General Public License v2.1 | 5 votes |
public static void initializeTable(JTable table) { table.setCellSelectionEnabled(false); table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); table.setFocusable(false); table.setRowHeight(21); table.getTableHeader().setReorderingAllowed(false); }
Example 17
Source File: ElementsTableComponent.java From mzmine2 with GNU General Public License v2.0 | 5 votes |
public ElementsTableComponent() { super(new BorderLayout()); elementsTableModel = new ElementsTableModel(); elementsTable = new JTable(elementsTableModel); elementsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); elementsTable.setRowSelectionAllowed(true); elementsTable.setColumnSelectionAllowed(false); elementsTable.setDefaultRenderer(Object.class, new ComponentCellRenderer(smallFont)); elementsTable.getTableHeader().setReorderingAllowed(false); elementsTable.getTableHeader().setResizingAllowed(false); elementsTable.setPreferredScrollableViewportSize(new Dimension(200, 80)); JScrollPane elementsScroll = new JScrollPane(elementsTable); add(elementsScroll, BorderLayout.CENTER); // Add buttons JPanel buttonsPanel = new JPanel(); BoxLayout buttonsPanelLayout = new BoxLayout(buttonsPanel, BoxLayout.Y_AXIS); buttonsPanel.setLayout(buttonsPanelLayout); addElementButton = GUIUtils.addButton(buttonsPanel, "Add", null, this); removeElementButton = GUIUtils.addButton(buttonsPanel, "Remove", null, this); add(buttonsPanel, BorderLayout.EAST); this.setPreferredSize(new Dimension(300, 100)); }
Example 18
Source File: ScreenInfoPanel.java From hprof-tools with MIT License | 4 votes |
public ScreenInfoPanel(@Nonnull final TabbedInfoWindow mainWindow, @Nonnull List<Screen> screens) { super(new BorderLayout()); JPopupMenu popupMenu = new JPopupMenu(); JMenuItem item = new JMenuItem("Inspect View"); item.addActionListener(new AbstractAction() { @Override public void actionPerformed(ActionEvent actionEvent) { mainWindow.showInstancesListTab(rightClickedViewed.getClassName(), Collections.singletonList(rightClickedViewed.getInstance())); } }); popupMenu.add(item); imagePanel = new ImagePanel(); viewTree = new JTree(new DefaultMutableTreeNode("Loading...")); viewTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); viewTree.addTreeSelectionListener(this); viewTree.addMouseListener(new PopupListener(popupMenu)); JScrollPane treeScroller = new JScrollPane(viewTree); rootPicker = new JComboBox(new Vector<Object>(screens)); rootPicker.addItemListener(this); JPanel settingsPanel = new JPanel(new GridLayout(1, 2)); showBoundsBox = new JCheckBox("Show layout bounds", true); showBoundsBox.addItemListener(this); forceAlpha = new JCheckBox("Force alpha", true); forceAlpha.addItemListener(this); settingsPanel.add(showBoundsBox); settingsPanel.add(forceAlpha); settingsPanel.setBorder(new EmptyBorder(10, 0, 0, 0)); infoTable = new JTable(); infoTable.setRowSelectionAllowed(false); infoTable.setColumnSelectionAllowed(false); infoTable.setCellSelectionEnabled(false); infoTable.setShowGrid(true); JPanel bottomPanel = new JPanel(new BorderLayout()); bottomPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); bottomPanel.add(infoTable, BorderLayout.CENTER); bottomPanel.add(infoTable.getTableHeader(), BorderLayout.NORTH); bottomPanel.add(settingsPanel, BorderLayout.SOUTH); JPanel leftPanel = new JPanel(new BorderLayout()); leftPanel.add(rootPicker, BorderLayout.NORTH); leftPanel.add(treeScroller, BorderLayout.CENTER); leftPanel.add(bottomPanel, BorderLayout.SOUTH); // Split pane for the tree and image views JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT); splitPane.setLeftComponent(leftPanel); splitPane.setRightComponent(imagePanel); add(splitPane, BorderLayout.CENTER); selectedScreen = screens.get(0); update(); }
Example 19
Source File: LibraryPanel.java From HubPlayer with GNU General Public License v3.0 | 4 votes |
/** * This method is called from within the constructor to initialize the form. * WARNING: Do NOT modify this code. The content of this method is always * regenerated by the Form Editor. */ @SuppressWarnings({ "unchecked", "serial" }) // <editor-fold defaultstate="collapsed" desc="Generated Code"> private void initComponents() { aScrollPanel = new JScrollPane(); dataTable = new JTable(); libraryTableModel = new LibraryTableModel(); libraryOperation = new LibraryOperation(); aToolBar = new JToolBar(); moreSearch = new JButton(); setLayout(new BorderLayout()); aScrollPanel .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER); aScrollPanel .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED); aScrollPanel.setMaximumSize(new Dimension(615, 481)); // 设置20行空数据 dataTable.setModel(libraryTableModel); libraryTableModel.setLibraryOperation(libraryOperation); // 定义"操作栏"的渲染器 显示按钮 dataTable.getColumn("操作").setCellRenderer( new DefaultTableCellRenderer() { @Override public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { return value instanceof JPanel ? (JPanel) value : super .getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); } }); // 定义"操作栏"的编辑器 响应按钮事件 dataTable.getColumn("操作").setCellEditor(new CellEditor()); dataTable.setColumnSelectionAllowed(true); dataTable.setRowHeight(23); aScrollPanel.setViewportView(dataTable); dataTable.getColumnModel().getSelectionModel() .setSelectionMode(ListSelectionModel.SINGLE_SELECTION); add(aScrollPanel, BorderLayout.CENTER); aToolBar.setFloatable(false); aToolBar.setRollover(true); aToolBar.setOpaque(false); moreSearch.setText("更多数据"); moreSearch.setFocusable(false); moreSearch.setHorizontalTextPosition(SwingConstants.CENTER); moreSearch.setVerticalTextPosition(SwingConstants.BOTTOM); // moreSearch.setEnabled(false); aToolBar.add(moreSearch); Box box = Box.createVerticalBox(); box.setBorder(BorderFactory.createLineBorder(Color.BLACK)); box.setOpaque(true); box.add(aToolBar); add(box, BorderLayout.SOUTH); }
Example 20
Source File: ProjectParametersSetupDialog.java From mzmine2 with GNU General Public License v2.0 | 4 votes |
private void initComponents() { panelParameterValues = new JPanel(new BorderLayout()); scrollParameterValues = new JScrollPane(); tablemodelParameterValues = new ParameterTableModel(new RawDataFile[0], new Hashtable<UserParameter<?, ?>, Object[]>()); tableParameterValues = new JTable(tablemodelParameterValues); tableParameterValues.setColumnSelectionAllowed(true); tableParameterValues.setRowSelectionAllowed(false); scrollParameterValues.setViewportView(tableParameterValues); scrollParameterValues.setMinimumSize(new Dimension(100, 100)); scrollParameterValues.setPreferredSize(new Dimension(100, 100)); panelRemoveParameterButton = new JPanel(new FlowLayout(FlowLayout.LEFT)); buttonAddParameter = new JButton("Add new parameter"); buttonAddParameter.addActionListener(this); buttonImportParameters = new JButton("Import parameters and values..."); buttonImportParameters.addActionListener(this); buttonRemoveParameter = new JButton("Remove selected parameter"); buttonRemoveParameter.addActionListener(this); panelRemoveParameterButton.add(buttonAddParameter); panelRemoveParameterButton.add(buttonImportParameters); panelRemoveParameterButton.add(buttonRemoveParameter); panelParameterValues.add(scrollParameterValues, BorderLayout.CENTER); panelParameterValues.add(panelRemoveParameterButton, BorderLayout.SOUTH); panelParameterValues.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panelOKCancelButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT)); buttonOK = new JButton("OK"); buttonOK.addActionListener(this); buttonCancel = new JButton("Cancel"); buttonCancel.addActionListener(this); panelOKCancelButtons.add(buttonOK); panelOKCancelButtons.add(buttonCancel); setLayout(new BorderLayout()); add(panelParameterValues, BorderLayout.CENTER); add(panelOKCancelButtons, BorderLayout.SOUTH); pack(); }