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:com.sec.ose.osi.ui.frm.main.manage.ManagedProjectTableModel.java
public void setColumnType(JTable table) { table.setShowVerticalLines(false);/* w w w . j ava 2 s .c om*/ 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:com.floreantpos.bo.ui.explorer.MenuItemExplorer.java
public void resizeColumnWidth(JTable table) { final TableColumnModel columnModel = table.getColumnModel(); for (int column = 0; column < table.getColumnCount(); column++) { columnModel.getColumn(column).setPreferredWidth((Integer) getColumnWidth().get(column)); }//from w ww .jav a 2 s . c o m }
From source file:net.sf.jabref.gui.maintable.MainTable.java
private void setWidths() { // Setting column widths: int ncWidth = Globals.prefs.getInt(JabRefPreferences.NUMBER_COL_WIDTH); List<String> widthsFromPreferences = Globals.prefs.getStringList(JabRefPreferences.COLUMN_WIDTHS); TableColumnModel cm = getColumnModel(); cm.getColumn(0).setPreferredWidth(ncWidth); for (int i = 1; i < cm.getColumnCount(); i++) { MainTableColumn mainTableColumn = tableFormat.getTableColumn(cm.getColumn(i).getModelIndex()); if (SpecialFieldsUtils.FIELDNAME_RANKING.equals(mainTableColumn.getColumnName())) { cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); } else if (mainTableColumn.isIconColumn()) { cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL); cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL); cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL); } else {//from www .jav a2 s.c om List<String> allColumns = Globals.prefs.getStringList(JabRefPreferences.COLUMN_NAMES); // find index of current mainTableColumn in allColumns for (int j = 0; j < allColumns.size(); j++) { if (allColumns.get(j).equalsIgnoreCase(mainTableColumn.getDisplayName())) { try { // set preferred width by using found index j in the width array cm.getColumn(i).setPreferredWidth(Integer.parseInt(widthsFromPreferences.get(j))); } catch (NumberFormatException e) { LOGGER.info("Exception while setting column widths. Choosing default.", e); cm.getColumn(i).setPreferredWidth(BibtexSingleField.DEFAULT_FIELD_LENGTH); } break; } } } } }
From source file:nl.phanos.liteliveresultsclient.gui.ResultsWindows.java
public void resizeColumns() { // TODO add your handling code here: int tW = jTable1.getWidth(); TableColumnModel jTableColumnModel = jTable1.getColumnModel(); int cantCols = jTableColumnModel.getColumnCount(); if (jTable1.getModel().getColumnCount() > 0) { jTableColumnModel.getColumn(0).setPreferredWidth((int) (fontSize * 3.0)); jTableColumnModel.getColumn(1)//from www .j a va 2 s. co m .setPreferredWidth((int) Math.round(tW - (fontSize * 2.5) - (fontSize * 5.0))); jTableColumnModel.getColumn(2).setPreferredWidth((int) (fontSize * 5.0)); } }
From source file:com.openbravo.pos.sales.JTicketLines.java
/** Creates new form JLinesTicket */ public JTicketLines(AppView app, String propertyRowHeight, String propertyFontsize, String ticketline) { this.m_App = app; initComponents();/*from w w w. j av a2 s. c o m*/ m_jTicketTable.m_App = app; m_jTicketTable.propertyRowHeight = propertyRowHeight; ColumnTicket[] acolumns = new ColumnTicket[0]; if (ticketline != null) { try { if (m_sp == null) { SAXParserFactory spf = SAXParserFactory.newInstance(); m_sp = spf.newSAXParser(); } ColumnsHandler columnshandler = new ColumnsHandler(); m_sp.parse(new InputSource(new StringReader(ticketline)), columnshandler); acolumns = columnshandler.getColumns(); } catch (ParserConfigurationException ePC) { logger.log(Level.WARNING, LocalRes.getIntString("exception.parserconfig"), ePC); } catch (SAXException eSAX) { logger.log(Level.WARNING, LocalRes.getIntString("exception.xmlfile"), eSAX); } catch (IOException eIO) { logger.log(Level.WARNING, LocalRes.getIntString("exception.iofile"), eIO); } } Map<String, Integer> widths = PropertyUtil.getTicketLineWidths(m_App); for (ColumnTicket acolumn : acolumns) { Integer width = widths.get(acolumn.name); if (width == null) { continue; } acolumn.width = width; } m_jTableModel = new TicketTableModel(acolumns); m_jTicketTable.setModel(m_jTableModel); m_jTicketTable.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); TableColumnModel jColumns = m_jTicketTable.getColumnModel(); for (int i = 0; i < acolumns.length; i++) { jColumns.getColumn(i).setPreferredWidth(acolumns[i].width); jColumns.getColumn(i).setResizable(true); } PropertyUtil.ScaleScrollbar(m_App, m_jScrollTableTicket); m_jTicketTable.getTableHeader().setReorderingAllowed(false); // m_jTicketTable.setDefaultRenderer(Object.class, new // TicketCellRenderer(app, acolumns, propertyFontsize)); m_jTicketTable.setDefaultRenderer(Object.class, new RowHeightCellRenderer(app, acolumns, propertyFontsize, propertyRowHeight)); PropertyUtil.ScaleTableColumnFontsize(m_App, m_jTicketTable, "sales-tablecolumn-fontsize", "14"); m_jTicketTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); m_jTicketTable.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { JTable table = (JTable) me.getSource(); Point p = me.getPoint(); int row = table.rowAtPoint(p); if (me.getClickCount() == 2) { // your valueChanged overridden method listDoubleClickListener.valueChanged(new ListSelectionEvent(m_jTicketTable, row, row, false)); } } }); // reseteo la tabla... m_jTableModel.clear(); }
From source file:net.sf.jabref.gui.MainTable.java
private void setWidths() { // Setting column widths: int ncWidth = Globals.prefs.getInt(JabRefPreferences.NUMBER_COL_WIDTH); String[] widths = Globals.prefs.getStringArray(JabRefPreferences.COLUMN_WIDTHS); TableColumnModel cm = getColumnModel(); cm.getColumn(0).setPreferredWidth(ncWidth); for (int i = 1; i < tableFormat.padleft; i++) { // Check if the Column is an extended RankingColumn (and not a compact-ranking column) // If this is the case, set a certain Column-width, // because the RankingIconColumn needs some more width if (tableFormat.isRankingColumn(i)) { // Lock the width of ranking icon column. cm.getColumn(i).setPreferredWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); cm.getColumn(i).setMinWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); cm.getColumn(i).setMaxWidth(GUIGlobals.WIDTH_ICON_COL_RANKING); } else {// ww w . j a v a 2 s .c o m // Lock the width of icon columns. 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 = tableFormat.padleft; i < getModel().getColumnCount(); i++) { try { cm.getColumn(i).setPreferredWidth(Integer.parseInt(widths[i - tableFormat.padleft])); } catch (Throwable ex) { LOGGER.info("Exception while setting column widths. Choosing default.", ex); cm.getColumn(i).setPreferredWidth(GUIGlobals.DEFAULT_FIELD_LENGTH); } } }
From source file:com.mirth.connect.client.ui.components.MirthTreeTable.java
@Override public void setSortable(boolean enable) { super.setSortable(enable); JTableHeader header = getTableHeader(); if (enable) { if (treeTableSortAdapter == null) { treeTableSortAdapter = new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { JTableHeader h = (JTableHeader) e.getSource(); TableColumnModel columnModel = getColumnModel(); int viewColumn = h.columnAtPoint(e.getPoint()); int column = columnModel.getColumn(viewColumn).getModelIndex(); if (column != -1) { beforeSort(); // Toggle sort order (ascending <-> descending) SortableTreeTableModel model = (SortableTreeTableModel) getTreeTableModel(); model.setColumnAndToggleSortOrder(column); // Set sorting icon and current column index ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setSortingIcon(model.getSortOrder()); ((SortableHeaderCellRenderer) getTableHeader().getDefaultRenderer()) .setColumnIndex(column); saveSortPreferences(column); afterSort(); }/* w w w . ja v a 2s . c o m*/ } } }; header.addMouseListener(treeTableSortAdapter); } } else { if (treeTableSortAdapter != null) { header.removeMouseListener(treeTableSortAdapter); treeTableSortAdapter = null; } } }
From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java
public void setXLabel(String xLabel) { domainLabel = xLabel;/*from w w w .j a v a2s.c o m*/ TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(0).setHeaderValue(xLabel); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:edu.ucla.stat.SOCR.chart.SuperPieChart.java
public void setYLabel(String yLabel) { rangeLabel = yLabel;// w w w .ja va 2 s. c o m TableColumnModel columnModel = dataTable.getColumnModel(); columnModel.getColumn(1).setHeaderValue(yLabel); columnModel.getColumn(2).setHeaderValue("pullout flag"); dataTable.setTableHeader(new EditableHeader(columnModel)); }
From source file:com.diversityarrays.kdxplore.trials.TrialSelectionDialog.java
public TrialSelectionDialog(Window owner, String title, DALClient c, List<Trial> kdxTrials, Transformer<BackgroundRunner, TrialSearchOptionsPanel> searchOptionsPanelFactory) { super(owner, title, USE_TRIALS); setGlassPane(backgroundRunner.getBlockingPane()); searchOptionsPanel = searchOptionsPanelFactory.transform(backgroundRunner); helpInstructions = new JLabel(searchOptionsPanel.getHtmlHelp(GET_TRIALS)); kdxTrialByIdDownloaded = kdxTrials.stream().filter(t -> t.getIdDownloaded() != null) .collect(Collectors.toMap(Trial::getIdDownloaded, java.util.function.Function.identity())); trialRecordTable.setName(this.getClass().getName() + ".trialRecordTable"); //$NON-NLS-1$ TableColumnModel tcm = trialRecordTable.getColumnModel(); TableCellRenderer cellRenderer = new OptionalCheckboxRenderer("Already downloaded"); tcm.getColumn(trialRecordTableModel.getChosenColumnIndex()).setCellRenderer(cellRenderer); for (int col = tcm.getColumnCount(); --col >= 0;) { if ("TrialName".equals(trialRecordTable.getColumnName(col))) { TableColumn tc = tcm.getColumn(col); tc.setCellRenderer(new TrialNameCellRenderer()); break; }//from www .ja va 2 s .co m } findTrialRecords.setEnabled(false); searchOptionsPanel.addSearchOptionsChangeListener(searchOptionsListener); wantTrialUnits.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { filteringClauseUsed = null; handleSearchOptionsChoiceChanged(); } }); setDALClient(c); initialiseGui(); if (owner != null) { Dimension ownerSize = owner.getSize(); Dimension mySize = getSize(); int w = (ownerSize.width * 3) / 4; int h = (ownerSize.height * 3) / 4; if (w > mySize.width || h > mySize.height) { if (w > mySize.width) { mySize.width = w; } if (h > mySize.height) { mySize.height = h; } setSize(mySize); } } // TODO consider using setSize to increase to parent's width getOkAction().setEnabled(false); trialRecordTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { getOkAction().setEnabled(trialRecordTableModel.getAnyChosen()); } }); }