List of usage examples for javax.swing.table DefaultTableColumnModel addColumn
public void addColumn(TableColumn aColumn)
aColumn
to the end of the tableColumns
array. From source file:hermes.browser.dialog.GeneralRendererConfigPanel.java
public void setHermesConfig(HermesConfig hermesConfig) { this.hermesConfig = hermesConfig; initState();//from w w w. jav a 2 s .c o m configModel = new ListConfigTableModel(); for (MessageRenderer rConfig : HermesBrowser.getRendererManager().getRenderers()) { configModel.addItem(rConfig.getDisplayName()); } classTable.setModel(configModel); DefaultTableColumnModel cm = new DefaultTableColumnModel(); cm.addColumn(new TableColumn()); classTable.setColumnModel(cm); }
From source file:DefaultsDisplay.java
protected JTable createDefaultsTable() { JTable table = new JTable(new UIDefaultsTableModel()); table.setRowHeight(rowHeight);/* ww w. j a va 2 s . c om*/ table.setShowHorizontalLines(false); table.setShowVerticalLines(false); table.setIntercellSpacing(new Dimension(0, 0)); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); initFilters(table); DefaultTableColumnModel columnModel = new DefaultTableColumnModel(); Color rowColors[] = new Color[2]; rowColors[0] = UIManager.getColor("Table.background"); rowColors[1] = new Color((int) (rowColors[0].getRed() * .90), (int) (rowColors[0].getGreen() * .95), (int) (rowColors[0].getBlue() * .95)); int width = 0; TableColumn column = new TableColumn(); column.setCellRenderer(new KeyRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.KEY_COLUMN); column.setHeaderValue("Key"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new RowRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.TYPE_COLUMN); column.setHeaderValue("Type"); column.setPreferredWidth(250); columnModel.addColumn(column); width += column.getPreferredWidth(); column = new TableColumn(); column.setCellRenderer(new ValueRenderer(rowColors)); column.setModelIndex(UIDefaultsTableModel.VALUE_COLUMN); column.setHeaderValue("Value"); column.setPreferredWidth(300); columnModel.addColumn(column); width += column.getPreferredWidth(); table.setColumnModel(columnModel); table.setPreferredScrollableViewportSize(new Dimension(width, 12 * rowHeight)); return table; }
From source file:com.vgi.mafscaling.ClosedLoop.java
private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) { final JTable afrTable = new JTable() { private static final long serialVersionUID = 6526901361175099297L; public boolean isCellEditable(int row, int column) { return false; };//w w w . j a v a2 s. com }; DefaultTableColumnModel afrModel = new DefaultTableColumnModel(); final TableColumn afrColumn = new TableColumn(0, 250); afrColumn.setHeaderValue(tableName); afrModel.addColumn(afrColumn); JTableHeader lblAfrTableName = afrTable.getTableHeader(); lblAfrTableName.setColumnModel(afrModel); lblAfrTableName.setReorderingAllowed(false); DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer(); headerRenderer.setHorizontalAlignment(SwingConstants.LEFT); GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints(); gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0); gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START; gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL; gbc_lblAfrTableName.gridx = 0; gbc_lblAfrTableName.gridy = gridy; panel.add(lblAfrTableName, gbc_lblAfrTableName); afrTable.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { afrColumn.setWidth(afrTable.getWidth()); } }); afrTable.getTableHeader().setReorderingAllowed(false); afrTable.setColumnSelectionAllowed(true); afrTable.setCellSelectionEnabled(true); afrTable.setBorder(new LineBorder(new Color(0, 0, 0))); afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount)); Utils.initializeTable(afrTable, ColumnWidth); if (tableName.equals(Afr1TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } else if (tableName.equals(Afr2TableName)) { Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") }, { new DecimalFormat("#"), new DecimalFormat("#") } }; NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class); renderer.setFormats(formatMatrix); } GridBagConstraints gbc_afrTable = new GridBagConstraints(); gbc_afrTable.insets = new Insets(0, 0, 0, 0); gbc_afrTable.anchor = GridBagConstraints.PAGE_START; gbc_afrTable.gridx = 0; gbc_afrTable.gridy = gridy + 1; panel.add(afrTable, gbc_afrTable); excelAdapter.addTable(afrTable, true, false); return afrTable; }
From source file:forge.itemmanager.views.ItemListView.java
@Override public void setup(final ItemManagerConfig config, final Map<ColumnDef, ItemTableColumn> colOverrides) { final Iterable<T> selectedItemsBefore = getSelectedItems(); final DefaultTableColumnModel colmodel = new DefaultTableColumnModel(); //ensure columns ordered properly final List<ItemTableColumn> columns = new LinkedList<ItemTableColumn>(); for (final ItemColumnConfig colConfig : config.getCols().values()) { if (colOverrides == null || !colOverrides.containsKey(colConfig.getDef())) { columns.add(new ItemTableColumn(new ItemColumn(colConfig))); } else {/*ww w . j a va 2 s . com*/ columns.add(colOverrides.get(colConfig.getDef())); } } Collections.sort(columns, new Comparator<ItemTableColumn>() { @Override public int compare(final ItemTableColumn arg0, final ItemTableColumn arg1) { return Integer.compare(arg0.getIndex(), arg1.getIndex()); } }); //hide table header if only showing single string column final boolean hideHeader = (config.getCols().size() == 1 && config.getCols().containsKey(ColumnDef.STRING)); getPnlOptions().removeAll(); if (config.getShowUniqueCardsOption()) { final FCheckBox chkBox = new FCheckBox("Unique Cards Only", this.itemManager.getWantUnique()); chkBox.setFont(ROW_FONT); chkBox.setToolTipText("Toggle whether to show unique cards only"); chkBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent arg0) { final boolean wantUnique = chkBox.isSelected(); if (itemManager.getWantUnique() == wantUnique) { return; } itemManager.setWantUnique(wantUnique); itemManager.refresh(); if (itemManager.getConfig() != null) { itemManager.getConfig().setUniqueCardsOnly(wantUnique); } } }); getPnlOptions().add(chkBox); } int modelIndex = 0; for (final ItemTableColumn col : columns) { col.setModelIndex(modelIndex++); if (col.isVisible()) { colmodel.addColumn(col); } if (!hideHeader) { final FCheckBox chkBox = new FCheckBox( StringUtils.isEmpty(col.getShortName()) ? col.getLongName() : col.getShortName(), col.isVisible()); chkBox.setFont(ROW_FONT); chkBox.setToolTipText(col.getLongName()); chkBox.addChangeListener(new ChangeListener() { @Override public void stateChanged(final ChangeEvent arg0) { final boolean visible = chkBox.isSelected(); if (col.isVisible() == visible) { return; } col.setVisible(visible); if (col.isVisible()) { colmodel.addColumn(col); //move column into proper position final int oldIndex = colmodel.getColumnCount() - 1; int newIndex = col.getIndex(); for (int i = 0; i < col.getIndex(); i++) { if (!columns.get(i).isVisible()) { newIndex--; } } if (newIndex < oldIndex) { colmodel.moveColumn(oldIndex, newIndex); } } else { colmodel.removeColumn(col); } ItemManagerConfig.save(); } }); getPnlOptions().add(chkBox); } } if (hideHeader) { this.table.getTableHeader().setPreferredSize(new Dimension(0, 0)); } else { this.table.getTableHeader().setPreferredSize(new Dimension(0, ROW_HEIGHT)); } this.tableModel.addListeners(); this.table.setModel(this.tableModel); this.table.setColumnModel(colmodel); this.tableModel.setup(); this.refresh(selectedItemsBefore, 0, 0); }
From source file:v800_trainer.JCicloTronic.java
public void ChangeModel() { setCursor(new Cursor(Cursor.WAIT_CURSOR)); if (Hauptfenster != null) Hauptfenster.setSelectedIndex(0); DataProperty = new java.util.Properties(); jTableaccess = Datentabelle;/* ww w . j av a 2 s . c o m*/ String Filename = ""; String PlaceHolder = " "; File path = new File(Properties.getProperty("data.dir")); final String[] names = { "Datum", "Strecke", "Hhenmeter", "Zeit", "Titel" }; String[] list = path.list(new DirFilter("_Tour.cfg")); RowCount = 0; int Anzahlcfg = 0; if (list != null) Anzahlcfg = list.length; if (Anzahlcfg == 0) { setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); return; } Object datab[] = new Object[8]; ArrayList<Object[]> data_list = new ArrayList<Object[]>(); String hmString = ""; DecimalFormat form = new DecimalFormat("0");//Format ohne Kommastelle int j = 0; for (int i = 0; i < Anzahlcfg; i++) { //berprfen ob Hhenmeter eingetragen sind - ansonsten ermitteln (gilt fr neue Dateien) Filename = path.getPath() + SystemProperties.getProperty("file.separator") + list[i]; DataProperty = new java.util.Properties(); try { BufferedInputStream in = new BufferedInputStream(new FileInputStream(Filename)); DataProperty.load(in); in.close(); // prfen ob Datei gezeigt werden soll - Visible = 0 wenn Datei gelscht wurde if (!DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1")) continue; // wenn keine Hhenmeter eingetragen wurden (Erstaufruf) dann Hhenmeter ermitteln if (DataProperty.getProperty("Hoehenmeter", "novalue").equalsIgnoreCase("novalue") && DataProperty.getProperty("Visible", "1").equalsIgnoreCase("1") && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { JTourData Dummydata = new JTourData(Filename.substring(0, Filename.lastIndexOf('.')), this); DataProperty.setProperty("Hoehenmeter", form.format(Dummydata.ges_Hoehep)); try { Ausgabedatei = new FileOutputStream(Filename); DataProperty.store(Ausgabedatei, "Tour Eigenschaften: " + DataProperty.getProperty("Jahr") + DataProperty.getProperty("Monat") + DataProperty.getProperty("Tag") + DataProperty.getProperty("Stunde") + DataProperty.getProperty("Minute")); Ausgabedatei.close(); } catch (Exception e) { JOptionPane.showMessageDialog(null, " Fehler bei Speichern der DataProperty in ChangeModel", "Achtung!", JOptionPane.ERROR_MESSAGE); } } try { if (Integer.parseInt(DataProperty.getProperty("Visible", "1")) == 1 && !DataProperty.getProperty("Jahr", "keinEintrag").equalsIgnoreCase("keinEintrag")) { datab[0] = new String(" " + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Jahr", "1111")); datab[1] = PlaceHolder.substring(0, 9 - DataProperty.getProperty("Strecke", "0").length()) + DataProperty.getProperty("Strecke", "0") + " "; // data[j][1] = new String(DataProperty.getProperty("Strecke") + " "); datab[2] = new String( " " + HMS(java.lang.Integer.parseInt(DataProperty.getProperty("Dauer", "0")))); datab[3] = new String(DataProperty.getProperty("Titel", "---")); datab[4] = new String(DataProperty.getProperty("Jahr", "1111") + "." + DataProperty.getProperty("Monat", "11") + "." + DataProperty.getProperty("Tag", "11") + "." + DataProperty.getProperty("Stunde", "12") + "." + DataProperty.getProperty("Minute", "59")); datab[5] = new String(Filename.substring(0, Filename.lastIndexOf('.'))); datab[6] = new String(DataProperty.getProperty("Typ", "unbekannt")); hmString = "" + (int) Float.parseFloat(DataProperty.getProperty("Hoehenmeter", "0")); datab[7] = PlaceHolder.substring(0, 9 - hmString.length()) + hmString + " "; data_list.add(datab.clone()); } } catch (Exception e) { JOptionPane.showMessageDialog(null, "Fehler beim Erstellen der Datenliste " + e + " " + j, "Achtung!", JOptionPane.ERROR_MESSAGE); } } catch (Exception e) { System.out.println( "NEW IO-Fehler bei " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n " + e + " " + e.getLocalizedMessage() + "--File deleted"); e.printStackTrace(); JOptionPane.showMessageDialog(null, "Fehler beim Einlesen eines cfg Files " + path.getPath() + SystemProperties.getProperty("file.separator") + list[i] + "\n wurde gelscht!", "Achtung!", JOptionPane.ERROR_MESSAGE); File deletefile = new File( path.getPath() + SystemProperties.getProperty("file.separator") + list[i]); if (deletefile.exists()) deletefile.delete(); ChangeModel(); } } TableModel dataModel = new AbstractTableModel() { public int getColumnCount() { return names.length; } @Override public String getColumnName(int column) { return names[column]; } @Override public int getRowCount() { return data_list.size(); } @Override public Object getValueAt(int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); return data[col]; } @Override public void setValueAt(Object Ob, int row, int col) { Object data[] = new Object[8]; data = data_list.get(row); data[col] = Ob; data_list.set(row, data); } }; sorter = new TableSorter(dataModel); DatumColumn = new TableColumn(0); DatumColumn.setHeaderValue(names[0]); DatumColumn.setResizable(false); StreckeColumn = new TableColumn(1); StreckeColumn.setHeaderValue(names[1]); StreckeColumn.setResizable(false); HoeheColumn = new TableColumn(7); HoeheColumn.setHeaderValue(names[2]); HoeheColumn.setResizable(false); ZeitColumn = new TableColumn(2); ZeitColumn.setHeaderValue(names[3]); ZeitColumn.setResizable(false); NotizColumn = new TableColumn(3); NotizColumn.setHeaderValue(names[4]); DatumColumn.setMinWidth((int) 80 * FontSize / 12); StreckeColumn.setMinWidth((int) 65 * FontSize / 12); HoeheColumn.setMinWidth((int) 75 * FontSize / 12); ZeitColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setMinWidth((int) 75 * FontSize / 12); NotizColumn.setPreferredWidth((int) 75 * FontSize / 12 + 1000); DefaultTableCellRenderer TableCell = new DefaultTableCellRenderer(); TableCell.setHorizontalAlignment(JLabel.CENTER); HoeheColumn.setCellRenderer(TableCell); StreckeColumn.setCellRenderer(TableCell); DatumColumn.setCellRenderer(TableCell); ZeitColumn.setCellRenderer(TableCell); HoeheColumn.setHeaderRenderer(TableCell); StreckeColumn.setHeaderRenderer(TableCell); DatumColumn.setHeaderRenderer(TableCell); ZeitColumn.setHeaderRenderer(TableCell); NotizColumn.setHeaderRenderer(TableCell); DefaultTableColumnModel FileTableModel = new DefaultTableColumnModel(); FileTableModel.addColumn(DatumColumn); FileTableModel.addColumn(StreckeColumn); FileTableModel.addColumn(HoeheColumn); FileTableModel.addColumn(ZeitColumn); FileTableModel.addColumn(NotizColumn); Datentabelle.setModel(sorter); Datentabelle.setColumnModel(FileTableModel); Datentabelle.setRowHeight(FontSize + 5); sorter.addMouseListenerToHeaderInTable(Datentabelle); sorter.sortByColumn(0, false); Datentabelle.clearSelection(); SelectionChanged = true; JScrollBar verticaldummy = Datenliste_scroll_Panel.getVerticalScrollBar(); verticaldummy.setPreferredSize(new Dimension(FontSize + 10, FontSize + 10)); Datenliste_scroll_Panel.setVerticalScrollBar(verticaldummy); Update = false; Datenliste_Jahr.removeAllItems(); Datenliste_TourTyp.removeAllItems(); Auswahl_bersicht.removeAllItems(); JahrVergleich.removeAllItems(); InitComboJahr(); InitComboTyp(); Update = true; if (Datentabelle.getRowCount() != 0) { Datentabelle.addRowSelectionInterval(0, 0); Datenliste_scroll_Panel.getViewport().setViewPosition(new java.awt.Point(0, 0)); } if (Uebersicht != null) { Uebersicht = null; } jLabel69_Selektiert.setText(Datentabelle.getSelectedRowCount() + " / " + Datentabelle.getRowCount()); repaint(); setCursor(new Cursor(Cursor.DEFAULT_CURSOR)); }
From source file:pcgen.gui2.tabs.CompanionInfoTab.java
private void initComponents() { {/*from w w w . ja va 2 s . co m*/ DefaultTableColumnModel model = new DefaultTableColumnModel(); TableColumn column = new TableColumn(0); column.setResizable(true); model.addColumn(column); column = new TableColumn(1, 120, new ButtonCellRenderer(), null); column.setMaxWidth(120); column.setResizable(false); model.addColumn(column); companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); companionsTable.getTableHeader().setResizingAllowed(false); companionsTable.setAutoCreateColumnsFromModel(false); companionsTable.setColumnModel(model); } companionsTable.setIntercellSpacing(new Dimension(0, 0)); companionsTable.setFocusable(false); companionsTable.setRowHeight(23); companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLeftComponent(new JScrollPane(companionsTable)); JPanel rightPane = new JPanel(new BorderLayout()); infoPane.setOpaque(false); infoPane.setEditable(false); infoPane.setFocusable(true); infoPane.setContentType("text/html"); //$NON-NLS-1$ rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER); JPanel buttonPane = new JPanel(new FlowLayout()); buttonPane.add(loadButton); rightPane.add(buttonPane, BorderLayout.SOUTH); setRightComponent(rightPane); }