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:ThreadViewer.java
public ThreadViewer() { JTable table = new JTable(tableModel); table.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); TableColumnModel colModel = table.getColumnModel(); int numColumns = colModel.getColumnCount(); for (int i = 0; i < numColumns - 1; i++) { TableColumn col = colModel.getColumn(i); col.sizeWidthToFit();// w w w .j a v a2s . com col.setPreferredWidth(col.getWidth() + 5); col.setMaxWidth(col.getWidth() + 5); } JScrollPane sp = new JScrollPane(table); setLayout(new BorderLayout()); add(sp, BorderLayout.CENTER); }
From source file:SortedTableModel.java
public SimpleTableTestMultilineHeader() { Container pane = getContentPane(); pane.setLayout(new BorderLayout()); TableValues tv = new TableValues(); SortedTableModel stm = new SortedTableModel(tv); stm.sortRows(TableValues.ACCOUNT_BALANCE, true); table = new JTable(stm); table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(true); TableColumnModel tcm = table.getColumnModel(); TableColumn tc = tcm.getColumn(TableValues.GENDER); MultiLineHeaderRenderer mlhr = new MultiLineHeaderRenderer(); tc = tcm.getColumn(TableValues.ACCOUNT_BALANCE); tc.setHeaderRenderer(mlhr);//from w w w. j a va2 s . co m renderer = new SortedColumnHeaderRenderer(stm, mlhr); int count = tcm.getColumnCount(); for (int i = 0; i < count; i++) { tc = tcm.getColumn(i); tc.setHeaderRenderer(renderer); } JTableHeaderToolTips jthtt = new JTableHeaderToolTips(table.getColumnModel()); jthtt.setToolTips(new String[] { "Customer's First Name", "Customer's Last Name", "Customer's Date of Birth", "Customer's Account Balance", "Customer's Gender" }); table.setTableHeader(jthtt); JScrollPane jsp = new JScrollPane(table); pane.add(jsp, BorderLayout.CENTER); addHeaderListener(); }
From source file:edu.ucla.stat.SOCR.chart.SuperValueChart.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;/*ww w . java2 s. com*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(rangeLabel); }
From source file:net.sf.jabref.importer.ZipFileChooser.java
/** * New Zip file chooser./*w w w . j a va 2 s . c om*/ * * @param owner Owner of the file chooser * @param zipFile Zip-Fle to choose from, must be readable */ public ZipFileChooser(ImportCustomizationDialog importCustomizationDialog, ZipFile zipFile) { super(importCustomizationDialog, Localization.lang("Select file from ZIP-archive"), false); ZipFileChooserTableModel tableModel = new ZipFileChooserTableModel(zipFile, getSelectableZipEntries(zipFile)); JTable table = new JTable(tableModel); TableColumnModel cm = table.getColumnModel(); cm.getColumn(0).setPreferredWidth(200); cm.getColumn(1).setPreferredWidth(150); cm.getColumn(2).setPreferredWidth(100); JScrollPane sp = new JScrollPane(table, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setPreferredScrollableViewportSize(new Dimension(500, 150)); if (table.getRowCount() > 0) { table.setRowSelectionInterval(0, 0); } // cancel: no entry is selected JButton cancelButton = new JButton(Localization.lang("Cancel")); cancelButton.addActionListener(e -> dispose()); // ok: get selected class and check if it is instantiable as an importer JButton okButton = new JButton(Localization.lang("OK")); okButton.addActionListener(e -> { int row = table.getSelectedRow(); if (row == -1) { JOptionPane.showMessageDialog(this, Localization.lang("Please select an importer.")); } else { ZipFileChooserTableModel model = (ZipFileChooserTableModel) table.getModel(); ZipEntry tempZipEntry = model.getZipEntry(row); CustomImporter importer = new CustomImporter(); importer.setBasePath(model.getZipFile().getName()); String className = tempZipEntry.getName().substring(0, tempZipEntry.getName().lastIndexOf('.')) .replace("/", "."); importer.setClassName(className); try { ImportFormat importFormat = importer.getInstance(); importer.setName(importFormat.getFormatName()); importer.setCliId(importFormat.getId()); importCustomizationDialog.addOrReplaceImporter(importer); dispose(); } catch (IOException | ClassNotFoundException | InstantiationException | IllegalAccessException exc) { LOGGER.warn("Could not instantiate importer: " + importer.getName(), exc); JOptionPane.showMessageDialog(this, Localization.lang("Could not instantiate %0 %1", importer.getName() + ":\n", exc.getMessage())); } } }); // Key bindings: JPanel mainPanel = new JPanel(); //ActionMap am = mainPanel.getActionMap(); //InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW); //im.put(Globals.getKeyPrefs().getKey(KeyBinds.CLOSE_DIALOG), "close"); //am.put("close", closeAction); mainPanel.setLayout(new BorderLayout()); mainPanel.add(sp, BorderLayout.CENTER); JPanel optionsPanel = new JPanel(); optionsPanel.add(okButton); optionsPanel.add(cancelButton); optionsPanel.add(Box.createHorizontalStrut(5)); getContentPane().add(mainPanel, BorderLayout.CENTER); getContentPane().add(optionsPanel, BorderLayout.SOUTH); this.setSize(getSize()); pack(); this.setLocationRelativeTo(importCustomizationDialog); new FocusRequester(table); }
From source file:com.emr.schemas.ButtonColumn.java
/** * Create the ButtonColumn to be used as a renderer and editor. The * renderer and editor will automatically be installed on the TableColumn * of the specified column.//from www. j a va 2 s. c om * * @param table the table containing the button renderer/editor * @param action the Action to be invoked when the button is invoked * @param column the column to which the button renderer/editor is added */ public ButtonColumn(JTable table, Action action, int column, String btnText) { this.table = table; this.action = action; this.btnText = btnText; renderButton = new JButton(); editButton = new JButton(); editButton.setFocusPainted(false); editButton.addActionListener(this); originalBorder = editButton.getBorder(); setFocusBorder(new LineBorder(Color.BLUE)); TableColumnModel columnModel = table.getColumnModel(); columnModel.getColumn(column).setCellRenderer(this); columnModel.getColumn(column).setCellEditor(this); table.addMouseListener(this); }
From source file:edu.ucla.stat.SOCR.chart.SuperCategoryChart_Stat.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;/*from w w w. j a v a2 s. c om*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(rangeLabel); }
From source file:edu.ucla.stat.SOCR.chart.SuperDotChart.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;//w w w . j a v a 2s. c om TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(yLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:com.sec.ose.osi.ui.frm.main.manage.AddProjectTableModel.java
public void setColumnView(JTable table) { table.setShowVerticalLines(false);/*from w ww . j a v a2s .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:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void resetTableHaderSize(JTable table, int panel_size) { int chg_w = (panel_size - col_width - 20) / 2; if (panel_size != col_width) { TableColumnModel cm = table.getColumnModel(); cm.getColumn(COL_PROJECT_NAME).setPreferredWidth(columnWidth[COL_PROJECT_NAME] + chg_w); cm.getColumn(COL_SOURCE_LOCATION).setPreferredWidth(columnWidth[COL_SOURCE_LOCATION] + chg_w); }/*from www . j ava 2 s.co m*/ }
From source file:edu.ucla.stat.SOCR.chart.demo.BoxAndWhiskerChartDemo2.java
public void setXLabel(String xLabel) { domainLabel = xLabel;//from ww w. j a va 2 s .c om TableColumnModel columnModel = dataTable.getColumnModel(); for (int i = 0; i < columnModel.getColumnCount(); i++) columnModel.getColumn(i).setHeaderValue("serie" + i); dataTable.setTableHeader(new EditableHeader(columnModel)); }