List of usage examples for javax.swing JTable setColumnSelectionAllowed
@BeanProperty(visualUpdate = true, description = "If true, an entire column is selected for each selected cell.") public void setColumnSelectionAllowed(boolean columnSelectionAllowed)
From source file:TableFeature.java
public TableFeature() { super("Simple JTable Test"); setSize(300, 200);// w w w. j av a 2 s.c om setDefaultCloseOperation(EXIT_ON_CLOSE); File pwd = new File("."); Object[][] stats = getFileStats(pwd); JTable jt = new JTable(stats, titles); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:MainClass.java
public MainClass() { super("Custom TableModel Test"); setSize(300, 200);/* w w w . ja v a2s . co m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); FileModel fm = new FileModel(); JTable jt = new JTable(fm); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:FileTable2.java
public FileTable2() { super("Custom TableModel Test"); setSize(300, 200);// w ww. ja va2 s . c o m setDefaultCloseOperation(EXIT_ON_CLOSE); FileModel fm = new FileModel(); JTable jt = new JTable(fm); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); jt.setColumnSelectionAllowed(true); jt.setDefaultRenderer(Number.class, new BigRenderer(1000)); JScrollPane jsp = new JScrollPane(jt); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void setColumnView(JTable table) { table.setShowVerticalLines(false);/*from ww w .j a v a 2 s .c om*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_SUBSEQUENT_COLUMNS); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; searchHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ISSELECT), ""); col = cm.getColumn(COL_ISSELECT); col.setHeaderRenderer(searchHeader); }
From source file:MainClass.java
public MainClass() { super("Row Header Test"); setSize(300, 200);// w w w . j a v a 2 s . co m setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } public Object getValueAt(int row, int col) { return data[col] + row; } }; TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { first = false; return; } tc.setMinWidth(150); super.addColumn(tc); } }; TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } } }; JTable jt = new JTable(tm, cm); JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); jt.setSelectionModel(headerColumn.getSelectionModel()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);/*from ww w . j a va2 s . c o m*/ table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(false); table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); table.setRowHeight(30); JTableHeader header = table.getTableHeader(); header.setPreferredSize(new java.awt.Dimension(table.getTableHeader().getWidth(), 30)); header.setFont(new Font("Arial", Font.BOLD, 12)); header.setReorderingAllowed(false); TableColumnModel cm = table.getColumnModel(); TableColumn col = null; analyzeHeader = new CheckBoxHeader(new CheckboxHeaderItemListener(table, COL_ANALYZE_TARGET), "Analyze Target"); col = cm.getColumn(COL_ANALYZE_TARGET); col.setHeaderRenderer(analyzeHeader); JCheckBox chkbox = new JCheckBox(); chkbox.setBackground(Color.white); chkbox.setHorizontalAlignment(JLabel.CENTER); col.setCellRenderer(new DefaultTableCellRenderer() { private static final long serialVersionUID = 1L; public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { ManagedProjectTableModel model = (ManagedProjectTableModel) table.getModel(); String sPrjName = (String) table.getValueAt(row, ManagedProjectTableModel.COL_PROJECT_NAME); OSIProjectInfo item = model.getProjectInfo(sPrjName); JCheckBox chkbox = new JCheckBox(); chkbox.setSelected(((Boolean) value).booleanValue()); if (item != null) { chkbox.setEnabled(item.isLocationValid()); } chkbox.setHorizontalAlignment(JLabel.CENTER); chkbox.setBackground(Color.white); return (Component) chkbox; } }); col.setCellEditor(new DefaultCellEditor(chkbox)); col = cm.getColumn(COL_ANALYZE_STATUS); col.setCellRenderer(new StatusIconCellRenderer()); col = cm.getColumn(COL_SOURCE_LOCATION); col.setCellRenderer(new FileBrowseCellRenderer()); col.setCellEditor(new FileBrowseCellEditor()); }
From source file:TableSorter.java
/** * @param table1/* w w w . j av a2 s. c o m*/ */ public void addMouseListenerToHeaderInTable(JTable table1) { table1.setColumnSelectionAllowed(false); setTableHeader(table1.getTableHeader()); }
From source file:RowHeaderTable.java
public RowHeaderTable() { super("Row Header Test"); setSize(300, 200);/*from w w w .ja va 2s .c o m*/ setDefaultCloseOperation(EXIT_ON_CLOSE); TableModel tm = new AbstractTableModel() { String data[] = { "", "a", "b", "c", "d", "e" }; String headers[] = { "Row #", "Column 1", "Column 2", "Column 3", "Column 4", "Column 5" }; public int getColumnCount() { return data.length; } public int getRowCount() { return 1000; } public String getColumnName(int col) { return headers[col]; } // Synthesize some entries using the data values & the row # public Object getValueAt(int row, int col) { return data[col] + row; } }; // Create a column model for the main table. This model ignores the // first // column added, and sets a minimum width of 150 pixels for all others. TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { // Drop the first column . . . that'll be the row header if (first) { first = false; return; } tc.setMinWidth(150); // just for looks, really... super.addColumn(tc); } }; // Create a column model that will serve as our row header table. This // model picks a maximum width and only stores the first column. TableColumnModel rowHeaderModel = new DefaultTableColumnModel() { boolean first = true; public void addColumn(TableColumn tc) { if (first) { tc.setMaxWidth(tc.getPreferredWidth()); super.addColumn(tc); first = false; } // Drop the rest of the columns . . . this is the header column // only } }; JTable jt = new JTable(tm, cm); // Set up the header column and get it hooked up to everything JTable headerColumn = new JTable(tm, rowHeaderModel); jt.createDefaultColumnsFromModel(); headerColumn.createDefaultColumnsFromModel(); // Make sure that selections between the main table and the header stay // in sync (by sharing the same model) jt.setSelectionModel(headerColumn.getSelectionModel()); // Make the header column look pretty //headerColumn.setBorder(BorderFactory.createEtchedBorder()); headerColumn.setBackground(Color.lightGray); headerColumn.setColumnSelectionAllowed(false); headerColumn.setCellSelectionEnabled(false); // Put it in a viewport that we can control a bit JViewport jv = new JViewport(); jv.setView(headerColumn); jv.setPreferredSize(headerColumn.getMaximumSize()); // With out shutting off autoResizeMode, our tables won't scroll // correctly (horizontally, anyway) jt.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // We have to manually attach the row headers, but after that, the // scroll // pane keeps them in sync JScrollPane jsp = new JScrollPane(jt); jsp.setRowHeader(jv); jsp.setCorner(ScrollPaneConstants.UPPER_LEFT_CORNER, headerColumn.getTableHeader()); getContentPane().add(jsp, BorderLayout.CENTER); }
From source file:net.pandoragames.far.ui.swing.FileListPanel.java
private void init(SwingConfig config, ComponentRepository componentRepository) { this.setLayout(new BorderLayout()); this.setBorder( BorderFactory.createEmptyBorder(0, SwingConfig.PADDING, SwingConfig.PADDING, SwingConfig.PADDING)); tableModel = componentRepository.getTableModel(); componentRepository.getResetDispatcher().addResetable(tableModel); componentRepository.getSearchBaseListener().addResetable(tableModel); componentRepository.getUndoListener().setTableModel(tableModel); JTable fileListTable = componentRepository.getFileSetTable(); int totalWidth = fileListTable.getPreferredSize().width; fileListTable.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); fileListTable.setColumnSelectionAllowed(true); fileListTable.getTableHeader().addMouseListener(new TableHeaderMouseListener()); fileListTable.getTableHeader().getColumnModel().getColumn(0) .setHeaderRenderer(new TableHeaderCheckBoxColumnRenderer()); fileListPopupMenu = new FileListPopupMenu(fileListTable, tableModel, componentRepository, config); fileListTable.setComponentPopupMenu(fileListPopupMenu); fileListTable.addMouseListener(new FileViewOpener(fileListTable, componentRepository.getRootWindow(), config, componentRepository)); fileListTable.getColumnModel().getColumn(0).setPreferredWidth(20); fileListTable.getColumnModel().getColumn(0).setMaxWidth(20); fileListTable.getColumnModel().getColumn(1).setCellRenderer(new TargetFileListTableCellRenderer()); fileListTable.getColumnModel().getColumn(1).setPreferredWidth(2 * totalWidth / 5); fileListTable.getColumnModel().getColumn(2).setCellRenderer(new PathColumnRenderer()); fileListTable.getColumnModel().getColumn(3).setCellRenderer(new InfoColumnRenderer(config)); JScrollPane scrollPane = new JScrollPane(fileListTable); this.add(scrollPane, BorderLayout.CENTER); SelectCounter fileCounter = new SelectCounter(); fileCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); fileCounter.setForeground(Color.GRAY); ErrorCounter errorCounter = new ErrorCounter(); errorCounter.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); JPanel counterLine = new JPanel(); counterLine.setLayout(new BorderLayout()); counterLine.add(fileCounter, BorderLayout.WEST); counterLine.add(errorCounter, BorderLayout.EAST); JProgressBar progressBar = new JProgressBar(); progressBar.setEnabled(false);//from ww w . j a v a 2 s.c o m progressBar.setMaximumSize(new Dimension(100, 20)); progressBar.setBorder(BorderFactory.createEmptyBorder(1, SwingConfig.PADDING, 2, SwingConfig.PADDING)); componentRepository.getProgressBarUpdater().setProgressBar(progressBar); JPanel progressBarPanel = new JPanel(); progressBarPanel.add(progressBar); counterLine.add(progressBarPanel, BorderLayout.CENTER); counterLine.setBorder(BorderFactory.createLineBorder(Color.GRAY, 1)); this.add(counterLine, BorderLayout.SOUTH); tableModel.addTableModelListener(new ColumnCountListener(fileCounter)); tableModel.addTableModelListener(errorCounter); componentRepository.getResetDispatcher().addResetable(fileCounter); componentRepository.getSearchBaseListener().addResetable(fileCounter); componentRepository.getOperationCallBackListener().addComponentStartReseted(fileCounter, OperationType.FIND); componentRepository.getResetDispatcher().addResetable(errorCounter); componentRepository.getSearchBaseListener().addResetable(errorCounter); viewAction = new ActionView(componentRepository, config); }
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);//from w w w. j ava2 s . 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(); }