List of usage examples for javax.swing.table TableColumnModel getColumn
public TableColumn getColumn(int columnIndex);
TableColumn
object for the column at columnIndex
. From source file:finalproject.BloodGlucoseGUI.java
/** * Constructor//from www . j a v a 2s . co m * Creates new form BloodGlucoseGUI */ // I would put most of it in initComponents if I could // edit that generated code. public BloodGlucoseGUI() { initComponents(); //jfc = new JFileChooser("Resources/Data"); // For "commercial" use //jfc = new JFileChooser("C:\\Program Files\\BGDataAnalysis\\Data"); jfc = new JFileChooser("C:\\BGDataAnalysis\\Data"); tabMod = new MyTableModel(); jTable2.setModel(tabMod); listMod = new DefaultListModel(); jList1.setModel(listMod); JTableHeader th = jTable2.getTableHeader(); TableColumnModel tcm = th.getColumnModel(); TableColumn tc = tcm.getColumn(0); tc.setHeaderValue("Time"); tc = tcm.getColumn(1); tc.setHeaderValue("Blood Glucose"); th.repaint(); notesTextArea.setLineWrap(true); notesTextArea.setWrapStyleWord(true); notesTextArea.addKeyListener(new KeyAdapter() { public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER) { e.consume(); ErrorGUIs.Popup pu = new ErrorGUIs.Popup(); pu.add("Please don't press the ENTER button!"); pu.display(); } } }); }
From source file:edu.ucla.stat.SOCR.chart.SuperIntervalXYChart_Time.java
public void setXLabel(String xLabel) { domainLabel = xLabel;/* w w w . j a v a2s .c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); for (int i = 0; i < columnModel.getColumnCount() / 2; i++) columnModel.getColumn(2 * i).setHeaderValue(xLabel + ":" + i); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:ErroresPorTraza.TabbedForm.java
private void setSizeColumn(JTable jTable1) { TableColumnModel model1 = jTable1.getColumnModel(); model1.getColumn(0).setPreferredWidth(300); model1.getColumn(1).setPreferredWidth(75); }
From source file:ErroresPorTraza.TabbedForm.java
private void setSizeColumnMil(JTable jTable1) { TableColumnModel model1 = jTable1.getColumnModel(); model1.getColumn(0).setPreferredWidth(195); model1.getColumn(1).setPreferredWidth(60); model1.getColumn(2).setPreferredWidth(60); model1.getColumn(3).setPreferredWidth(60); }
From source file:net.sf.jabref.gui.search.SearchResultsDialog.java
/** * Set column widths according to which field is shown, and lock icon columns * to a suitable width./*from ww w .j a v a 2 s .co m*/ */ private void setWidths() { TableColumnModel cm = entryTable.getColumnModel(); for (int i = 0; i < PAD; i++) { cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL); cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL); cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL); } for (int i = 0; i < FIELDS.length; i++) { int width = InternalBibtexFields.getFieldLength(FIELDS[i]); cm.getColumn(i + PAD).setPreferredWidth(width); } }
From source file:com.frostwire.gui.library.LibraryDeviceTableMediator.java
protected void setDefaultEditors() { TableColumnModel model = TABLE.getColumnModel(); TableColumn tc;/* w w w.j av a2s .c o m*/ tc = model.getColumn(LibraryDeviceTableDataLine.TITLE_IDX); tc.setCellEditor(new LibraryNameHolderEditor()); }
From source file:net.sf.jabref.gui.openoffice.StyleSelectDialog.java
private void setupTable() { styles = new BasicEventList<>(); EventList<OOBibStyle> sortedStyles = new SortedList<>(styles); tableModel = (DefaultEventTableModel<OOBibStyle>) GlazedListsSwing .eventTableModelWithThreadProxyList(sortedStyles, new StyleTableFormat()); table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(100); cm.getColumn(1).setPreferredWidth(200); cm.getColumn(2).setPreferredWidth(80); selectionModel = (DefaultEventSelectionModel<OOBibStyle>) GlazedListsSwing .eventSelectionModelWithThreadProxyList(sortedStyles); table.setSelectionModel(selectionModel); table.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.addMouseListener(new MouseAdapter() { @Override//from ww w .j a v a2s . com public void mousePressed(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } @Override public void mouseReleased(MouseEvent mouseEvent) { if (mouseEvent.isPopupTrigger()) { tablePopup(mouseEvent); } } }); selectionModel.getSelected().addListEventListener(new EntrySelectionListener()); }
From source file:TableRowColumnTest.java
public PlanetTableFrame() { setTitle("TableRowColumnTest"); setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); TableModel model = new DefaultTableModel(cells, columnNames) { public Class<?> getColumnClass(int c) { return cells[0][c].getClass(); }/*from w ww .jav a2s . c om*/ }; table = new JTable(model); table.setRowHeight(100); table.getColumnModel().getColumn(COLOR_COLUMN).setMinWidth(250); table.getColumnModel().getColumn(IMAGE_COLUMN).setMinWidth(100); final TableRowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); sorter.setComparator(COLOR_COLUMN, new Comparator<Color>() { public int compare(Color c1, Color c2) { int d = c1.getBlue() - c2.getBlue(); if (d != 0) return d; d = c1.getGreen() - c2.getGreen(); if (d != 0) return d; return c1.getRed() - c2.getRed(); } }); sorter.setSortable(IMAGE_COLUMN, false); add(new JScrollPane(table), BorderLayout.CENTER); removedRowIndices = new HashSet<Integer>(); removedColumns = new ArrayList<TableColumn>(); final RowFilter<TableModel, Integer> filter = new RowFilter<TableModel, Integer>() { public boolean include(Entry<? extends TableModel, ? extends Integer> entry) { return !removedRowIndices.contains(entry.getIdentifier()); } }; // create menu JMenuBar menuBar = new JMenuBar(); setJMenuBar(menuBar); JMenu selectionMenu = new JMenu("Selection"); menuBar.add(selectionMenu); rowsItem = new JCheckBoxMenuItem("Rows"); columnsItem = new JCheckBoxMenuItem("Columns"); cellsItem = new JCheckBoxMenuItem("Cells"); rowsItem.setSelected(table.getRowSelectionAllowed()); columnsItem.setSelected(table.getColumnSelectionAllowed()); cellsItem.setSelected(table.getCellSelectionEnabled()); rowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setRowSelectionAllowed(rowsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(rowsItem); columnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setColumnSelectionAllowed(columnsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(columnsItem); cellsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { table.clearSelection(); table.setCellSelectionEnabled(cellsItem.isSelected()); updateCheckboxMenuItems(); } }); selectionMenu.add(cellsItem); JMenu tableMenu = new JMenu("Edit"); menuBar.add(tableMenu); JMenuItem hideColumnsItem = new JMenuItem("Hide Columns"); hideColumnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedColumns(); TableColumnModel columnModel = table.getColumnModel(); // remove columns from view, starting at the last // index so that column numbers aren't affected for (int i = selected.length - 1; i >= 0; i--) { TableColumn column = columnModel.getColumn(selected[i]); table.removeColumn(column); // store removed columns for "show columns" command removedColumns.add(column); } } }); tableMenu.add(hideColumnsItem); JMenuItem showColumnsItem = new JMenuItem("Show Columns"); showColumnsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { // restore all removed columns for (TableColumn tc : removedColumns) table.addColumn(tc); removedColumns.clear(); } }); tableMenu.add(showColumnsItem); JMenuItem hideRowsItem = new JMenuItem("Hide Rows"); hideRowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedRows(); for (int i : selected) removedRowIndices.add(table.convertRowIndexToModel(i)); sorter.setRowFilter(filter); } }); tableMenu.add(hideRowsItem); JMenuItem showRowsItem = new JMenuItem("Show Rows"); showRowsItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { removedRowIndices.clear(); sorter.setRowFilter(filter); } }); tableMenu.add(showRowsItem); JMenuItem printSelectionItem = new JMenuItem("Print Selection"); printSelectionItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent event) { int[] selected = table.getSelectedRows(); System.out.println("Selected rows: " + Arrays.toString(selected)); selected = table.getSelectedColumns(); System.out.println("Selected columns: " + Arrays.toString(selected)); } }); tableMenu.add(printSelectionItem); }
From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java
public void setXLabel(String xLabel) { domainLabel = xLabel;// w w w .j av a2s. c o m TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(domainLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:edu.ucla.stat.SOCR.chart.SuperXYZChart.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;/*from w w w . j av a 2 s.c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(1).setHeaderValue(rangeLabel); columnModel.getColumn(2).setHeaderValue("Z"); dataTable.setTableHeader(new EditableHeader(columnModel)); }