private JPanel createDynamicCenterPanel(PrimitiveForm primitiveForm, DOTProperty property) { final JTable theTable = new JTable(); PrimitiveFormPropertyPair pfpPair = new PrimitiveFormPropertyPair(primitiveForm.getName(), property); _dynamicTables.put(pfpPair, theTable); DOTPoint dotPoint = (DOTPoint) _dotDefinitionDialogFrame.getScratchDisplayObjectType(); final DynamicDOTItemManager tableModel = (DynamicDOTItemManager) dotPoint.getTableModel(primitiveForm, property); theTable.setModel(tableModel); class NumberComparator implements Comparator<Number> { public int compare(Number o1, Number o2) { final double d1 = o1.doubleValue(); final double d2 = o2.doubleValue(); if (d1 < d2) { return -1; } if (d1 == d2) { return 0; } return 1; } } TableRowSorter<DynamicDOTItemManager> tableRowSorter = new TableRowSorter<DynamicDOTItemManager>(); tableRowSorter.setModel(tableModel); tableRowSorter.setComparator(4, new NumberComparator()); tableRowSorter.setComparator(5, new NumberComparator()); theTable.setRowSorter(tableRowSorter); JButton newDOTItemButton = new JButton("Neue Zeile"); newDOTItemButton.setEnabled(_dotDefinitionDialogFrame.isEditable()); JButton deleteDOTItemButton = new JButton("Zeile löschen"); deleteDOTItemButton.setEnabled(false); JButton showConflictsButton = new JButton("Zeige Konflikte"); addButtonListeners( primitiveForm, property, newDOTItemButton, deleteDOTItemButton, showConflictsButton); addListSelectionListener(theTable, deleteDOTItemButton); JPanel dotButtonsPanel = new JPanel(); dotButtonsPanel.setLayout(new SpringLayout()); dotButtonsPanel.add(newDOTItemButton); dotButtonsPanel.add(deleteDOTItemButton); dotButtonsPanel.add(showConflictsButton); dotButtonsPanel.setBorder(BorderFactory.createEmptyBorder(5, 10, 5, 10)); SpringUtilities.makeCompactGrid(dotButtonsPanel, 1, 5, 20); JPanel thePanel = new JPanel(); thePanel.setLayout(new SpringLayout()); thePanel.setBorder(BorderFactory.createMatteBorder(2, 2, 2, 2, Color.BLACK)); thePanel.add(new JScrollPane(theTable)); thePanel.add(dotButtonsPanel); SpringUtilities.makeCompactGrid(thePanel, 2, 20, 5); return thePanel; }
/** * Set the current open DarwinCSV. You should really, really, really setCurrentCSV(null) before * you load a new DarwinCSV. * * @param csv The new DarwinCSV object. */ private void setCurrentCSV(DarwinCSV csv) { // Clear the old currentCSV object and matchAgainst object. currentCSV = null; matchAgainst(null); // Load the new currentCSV object. currentCSV = csv; table.removeAll(); table.setDefaultRenderer(Name.class, this); // Set the currentCSV // TODO: This causes an exception occasionally, because we shouldn't // be calling setModel outside of the Event Queue thread; however, we're // currently in a worker thread, so dipping back into the Event thread // would just cause more problems. Sorry! if (csv != null) { table.setModel(currentCSV.getRowIndex()); } else { table.setModel(blankDataModel); } columnInfoPanel.loadedFileChanged(csv); columnInfoPanel.columnChanged(-1); table.repaint(); }
public void setResultSet(DiskResultSet rset) throws Exception { set = rset; max = rset.getRowCount(); table.setModel(model); table.setModel(this); offset = 0; scrollBar.setValue(0); scrollBar.setMaximum((max < window ? 0 : max - window)); }
private void init(final EncodeTableModel model) { setModal(true); setTitle("Encode Production Data"); table.setAutoCreateRowSorter(true); table.setModel(model); table.setRowSorter(model.getSorter()); try { rowCountLabel.setText(numberFormatter.valueToString(table.getRowCount()) + " rows"); } catch (ParseException e) { } table.setRowSelectionAllowed(false); table.setColumnSelectionAllowed(false); filterTextField .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { updateFilter(); } public void insertUpdate(DocumentEvent e) { updateFilter(); } public void removeUpdate(DocumentEvent e) { updateFilter(); } }); }
public void moduleStateChanged() { if (myTable != null) { final DefaultTableModel tableModel = createModel(); myTable.setModel(tableModel); myRemoveButton.setEnabled(tableModel.getRowCount() > 0); } }
/** * This method initializes ActiveAggTable * * @return javax.swing.JTable */ private JTable getActiveAggTable() { if (ActiveAggTable == null) { ActiveAggTable = new JTable(); controller.activeAgg_ = new ActiveAggTableModel(); controller.activeAgg_.init(controller); ActiveAggTable.setModel(controller.activeAgg_); ActiveAggTable.addMouseListener( new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() == 2) { int row = ActiveAggTable.getSelectedRow(); if (row >= 0) { aggEditorFrame = new AggEditorFrame( (jAudioFeatureExtractor.Aggregators.Aggregator) controller.activeAgg_.getAggregator(row), controller); aggEditorFrame.setVisible(true); ((ActiveAggTableModel) ActiveAggTable.getModel()) .setAggregator( row, aggEditorFrame.getAggregator(), aggEditorFrame.isEdited()); } } } }); } return ActiveAggTable; }
@Override public void setModel(final TableModel model) { super.setModel(model); if (model instanceof SortableColumnModel) { final SortableColumnModel sortableModel = (SortableColumnModel) model; if (sortableModel.isSortable()) { final TableRowSorter<TableModel> rowSorter = createRowSorter(model); rowSorter.setSortsOnUpdates(isSortOnUpdates()); setRowSorter(rowSorter); final RowSorter.SortKey sortKey = sortableModel.getDefaultSortKey(); if (sortKey != null && sortKey.getColumn() >= 0 && sortKey.getColumn() < model.getColumnCount()) { if (sortableModel.getColumnInfos()[sortKey.getColumn()].isSortable()) { rowSorter.setSortKeys(Arrays.asList(sortKey)); } } } else { final RowSorter<? extends TableModel> rowSorter = getRowSorter(); if (rowSorter instanceof DefaultColumnInfoBasedRowSorter) { setRowSorter(null); } } } }
@SuppressWarnings("unchecked") private JComponent jRoom() { JPanel panel = new JPanel(); panel.setLayout(new BorderLayout()); panel.setBorder(BorderFactory.createTitledBorder("")); scrollPane = new JScrollPane(); jRoom = new JTable(); tableTitle.add("RoomID"); tableTitle.add("RoomNumber"); tableTitle.add("RoomType"); tableTitle.add("NumBeds"); tableTitle.add("RoomTypeRate"); tableTitle.add("RoomStatus"); tableTitle.add("Description"); model = new DefaultTableModel(tableRecords, tableTitle) { private static final long serialVersionUID = 1L; public boolean isCellEditable(int rowIndex, int mColIndex) { return false; } }; jRoom.setModel(model); jRoom.getTableHeader().setReorderingAllowed(false); scrollPane.setViewportView(jRoom); panel.add(scrollPane); return panel; }
BusinessPane() { setLayout(null); add(info_label); info_label.setBounds(10, 10, 300, 20); info_label.setFont(new Font("TimesRoman", Font.BOLD, 12)); add(info_scroll); info_scroll.setBounds(5, 35, 615, 400); info_name.add(columnName[0]); info_name.add(columnName[1]); info_name.add(columnName[2]); info_name.add(columnName[3]); DefaultTableModel info_model = new DefaultTableModel(info_data, info_name); info_table.setModel(info_model); info_table.getColumnModel().getColumn(0).setWidth(25); info_table.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 1) { // click to trigger the event // show_selected(); // System.out.print(table_selected(0)); } } }); add(B_refresh); B_refresh.setMargin(new java.awt.Insets(1, 1, 1, 1)); B_refresh.setBounds(530, 440, 90, 25); B_refresh.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { update_table(); } }); }
/** * Creates a new JTreeTable object. * * @param treeTableModel The tree table model. */ public JTreeTable(final TreeTableModel treeTableModel) { super(); // Create the tree. It will be used as a renderer and editor. tree = new TreeTableCellRenderer(treeTableModel); // Install a tableModel representing the visible rows in the tree. super.setModel(new TreeTableModelAdapter(treeTableModel, tree)); // Force the JTable and JTree to share their row selection models. ListToTreeSelectionModelWrapper selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModel.class, tree); setDefaultEditor(TreeTableModel.class, new TreeTableCellEditor()); // No grid. setShowGrid(false); // No intercell spacing setIntercellSpacing(new Dimension(0, 0)); // And update the height of the trees row to match that of // the table. if (tree.getRowHeight() < 1) { // Metal looks better like this. setRowHeight(18); } }
public void update() { infoPanel.update(); Object[][] history = new Object[account.getHistory().size()][5]; int i = 0; for (Transaction t : account.getHistory()) { history[i][0] = t.getType(); BigDecimal amount; BigDecimal balance; if (account.getType().isLoan()) { amount = (t.getType().isPositive() ? t.getAmount().negate() : t.getAmount()); balance = t.getBalance().negate(); } else { amount = (t.getType().isPositive() ? t.getAmount() : t.getAmount().negate()); balance = t.getBalance(); } history[i][1] = FORMATTER.valueToString(amount); history[i][2] = FORMATTER.valueToString(balance); history[i][3] = t.getTimestamp(); history[i][4] = t.getFraudStatus(); i++; } historyTable.setModel( new javax.swing.table.DefaultTableModel( history, new String[] {"Type", "Amount", "Balance", "Month", "Flag"}) { @Override public boolean isCellEditable(int rowIndex, int columnIndex) { return false; } }); historyTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); historyTable.revalidate(); }
stab(ResultSet k) { super("PATIENT FOUND"); String[] chd = { "Date", "Patient ID", "Name", "Gender", "Age", "Weight", "Address", "Contact No.", "Doctor Name", "Symptoms", "Dignosis", "Fee: Rs.", "Blood Group" }; // DefaultTableModel dtm=new DefaultTableModel(); // jt.setModel(new DefaultTableModel(arr,chd)); jt = new JTable(); jsp = new JScrollPane(jt); btn = new JButton("CLOSE"); btn.addActionListener(this); int i = 0; try { while (k.next()) { arr[i][0] = k.getString(1); // System.out.println("ddddddddddddd"+arr[i][0]); arr[i][1] = "" + k.getInt(2); arr[i][2] = k.getString(3) + " " + k.getString(4) + " " + k.getString(5); arr[i][3] = k.getString(6); arr[i][4] = "" + k.getInt(7); arr[i][5] = k.getString(8); arr[i][6] = k.getString(9); arr[i][7] = k.getString(10); arr[i][8] = k.getString(11); arr[i][9] = k.getString(12); arr[i][10] = k.getString(13); arr[i][11] = "" + k.getInt(14); arr[i][12] = k.getString(15); arr[i][13] = k.getString(16); // dtm.insertRow(i,new Object[]{patient.rs.getString(1), // patient.rs.getInt(2),patient.rs.getString(3)+patient.rs.getString(4)+patient.rs.getString(5),patient.rs.getString(6),patient.rs.getInt(7),patient.rs.getString(8),patient.rs.getString(9),patient.rs.getString(10),patient.rs.getString(11),patient.rs.getString(12),patient.rs.getString(13),patient.rs.getInt(14)}); i++; } } catch (Exception e12) { System.out.println("" + e12); } jt.setModel(new DefaultTableModel(arr, chd)); Container con = getContentPane(); con.setLayout(null); jsp.setBounds(20, 20, 1230, 600); btn.setBounds(685, 630, 100, 30); add(jsp); add(btn); setSize(1330, 800); setVisible(true); }
public void setMetricsResults(MetricDisplaySpecification displaySpecification, MetricsRun run) { final MetricCategory[] categories = MetricCategory.values(); for (final MetricCategory category : categories) { final JTable table = tables.get(category); final String type = MetricsCategoryNameUtil.getShortNameForCategory(category); final MetricTableSpecification tableSpecification = displaySpecification.getSpecification(category); final MetricsResult results = run.getResultsForCategory(category); final MetricTableModel model = new MetricTableModel(results, type, tableSpecification); table.setModel(model); final Container tab = table.getParent().getParent(); if (model.getRowCount() == 0) { tabbedPane.remove(tab); continue; } final String longName = MetricsCategoryNameUtil.getLongNameForCategory(category); tabbedPane.add(tab, longName); final MyColumnListener columnListener = new MyColumnListener(tableSpecification, table); final TableColumnModel columnModel = table.getColumnModel(); columnModel.addColumnModelListener(columnListener); final int columnCount = columnModel.getColumnCount(); for (int i = 0; i < columnCount; i++) { final TableColumn column = columnModel.getColumn(i); column.addPropertyChangeListener(columnListener); } setRenderers(table, type); setColumnWidths(table, tableSpecification); } }
public ChartLegend(PrideChartManager managedPrideChart) { super(new BorderLayout()); Dimension dimension = new Dimension(200, 50); PrideChartLegend pcl = (PrideChartLegend) managedPrideChart.getPrideChart(); setVisible(managedPrideChart.isLegendVisible()); JTable chartLegend = new JTable(); DefaultTableModel model = new DefaultTableModel(); model.setColumnIdentifiers(pcl.getColumnNames()); for (Object left : pcl.getOrderedLegend()) { String right = pcl.getLegendMeaning(left.toString()); model.addRow(new Object[] {left, right}); } chartLegend.setModel(model); // chartLegend.setAutoCreateRowSorter(false); chartLegend.setFillsViewportHeight(true); chartLegend.getColumnModel().getColumn(0).setMaxWidth(100); JScrollPane scrollPane = new JScrollPane( chartLegend, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED); this.add(scrollPane, BorderLayout.CENTER); this.setPreferredSize(dimension); }
public void updateActionTableFor(EditorClient client) { if (client == null) { DefaultTableModel model = new DefaultTableModel(); tblActions.setModel(getClearTableModel()); return; } else if (currClient == client) { DefaultTableModel model = getClearTableModel(); Iterator i = client.getActions(self).iterator(); while (i.hasNext()) { EditorAction ea = (EditorAction) i.next(); model.addRow(ea.getTableRow()); } tblActions.setModel(model); } }
public void setModel(LogItemTableModel model) { this.model = model; logItemTable.setModel(model); logItemTable.getColumnModel().getColumn(0).setMinWidth(180); logItemTable.getColumnModel().getColumn(0).setMaxWidth(200); logItemTable.getColumnModel().getColumn(1).setMinWidth(50); logItemTable.getColumnModel().getColumn(1).setMaxWidth(80); logItemTable.setDefaultRenderer(Object.class, new LogEntryRenderer()); }
{ table = new JTable(); model.setErrors(errors); table.setModel(model); TableColumn detailsColumn = table.getColumnModel().getColumn(1); detailsColumn.setCellEditor(new DetailRenderer()); detailsColumn.setCellRenderer(new DetailRenderer()); detailsColumn.setPreferredWidth(15); table.getColumnModel().getColumn(0).setPreferredWidth(DEFAULT_FIRST_COMUMN_WIDTH); }
public void refresh() { Message message = new Message(); try { message = this.trainingTeaBLService.showFrameStrategy(); } catch (RemoteException e) { // TODO Auto-generated catch block e.printStackTrace(); } if (message.getMesType().equals(MessageType.traTea_showStrategy_fail)) { // JOptionPane.showMessageDialog(this, "整体框架策略尚未发布!"); jl1.setVisible(true); jb2.setEnabled(false); if (jsp1 != null) { jsp1.setVisible(false); } } else if (message.getMesType().equals(MessageType.traTea_showStrategy_success)) { jl1.setVisible(false); ArrayList<Dean> dean = message.getDeans(); ArrayList<String> attriOfDean = message.getAttriOfDean(); tm1 = new StrategyTableModel(dean, attriOfDean); if (jsp1 != null) { jt1.setModel(tm1); jsp1.setVisible(true); } else { jt1 = new JTable(); jt1.setModel(tm1); jsp1 = new JScrollPane(jt1); strategy.add(jsp1); } if (dean.size() >= 15) { jb1.setEnabled(false); } jb2.setEnabled(true); } else { JOptionPane.showMessageDialog(this, "你的网络貌似有点问题!"); } }
public void popuniObracuniJTableSaPodacimaOKlijentu(Klijent selektiraniKlijent) { TableModel obracuniTableModel; if (selektiraniKlijent != null) { obracuniTableModel = new ObracuniTableModel(selektiraniKlijent); } else { Klijent prazanKlijent = new Klijent(); prazanKlijent.setRacuni(new ArrayList<Racun>(0)); obracuniTableModel = new DostaveTableModel(prazanKlijent); } obracuniJTable.setModel(obracuniTableModel); }
public void setTournament(File file, Tournament newTournament) { assert newTournament != null; this.currentFile = file; this.tournament = newTournament; rosterModel = new RosterModel(newTournament); rosterTable.setModel(rosterModel); refresh(); }
public void setData(Map<String, User> users) { String[] columns = {"Name", "Block"}; Object[][] list = new Object[users.size()][2]; User[] userArray = users.values().stream().toArray(User[]::new); for (int i = 0; i < userArray.length; i++) { list[i][0] = userArray[i].getName(); list[i][1] = userArray[i].getBlock(); } TableModel tableModel = new DefaultTableModel(list, columns); userTable.setModel(tableModel); }
private void jbInit() throws Exception { setTitle("DIARIO CONTADO"); frmDatosVenta = new FrmDatosVenta(engine); frmDatosVenta.setLocationRelativeTo(this); getContentPane().setLayout(borderLayout1); jLabel1.setFont(new java.awt.Font("Arial", Font.PLAIN, 18)); jLabel1.setToolTipText(""); jLabel1.setText("DIARIO DE ENTRADAS"); pnlCentro.setLayout(borderLayout2); cmdCerrar.setText("CERRAR"); cmdCerrar.addActionListener(new FrmDiarioDeEntradas_cmdCerrar_actionAdapter(this)); cmdImprimir.setText("IMPRIMIR"); tblDiario.setBackground(new Color(255, 240, 255)); tblDiario.setFont(new java.awt.Font("Arial", Font.PLAIN, 12)); tblDiario.setModel(modelDiarioVentasDeContado1); tblDiario.addMouseListener(new FrmDiarioDeEntradas_tblDiario_mouseAdapter(this)); this.addWindowListener(new FrmDiarioDeEntradas_this_windowAdapter(this)); jLabel2.setFont(new java.awt.Font("Arial", Font.BOLD, 20)); jLabel2.setText("Total:"); lblTotal.setFont(new java.awt.Font("Arial", Font.BOLD, 20)); lblTotal.setText(""); this.getContentPane().setBackground(Color.white); this.addKeyListener(new FrmDiarioDeEntradas_this_keyAdapter(this)); pnlCentro.setBackground(Color.white); pnlNorte.setBackground(Color.white); pnlNorte.setLayout(borderLayout4); scrollDiario.getViewport().setBackground(Color.white); scrollDiario.setPreferredSize(new Dimension(800, 600)); lblFecha.setFont(new java.awt.Font("Arial", Font.BOLD, 16)); lblFecha.setText(""); jPanel1.setLayout(borderLayout3); pnlSur.setMaximumSize(new Dimension(4000, 200)); jPanel1.setBackground(Color.white); jPanel2.setBackground(Color.white); this.getContentPane().add(pnlCentro, java.awt.BorderLayout.CENTER); pnlCentro.add(pnlNorte, java.awt.BorderLayout.CENTER); pnlCentro.add(scrollDiario, java.awt.BorderLayout.NORTH); scrollDiario.getViewport().add(tblDiario); this.getContentPane().add(pnlSur, java.awt.BorderLayout.SOUTH); pnlSur.add(cmdImprimir); pnlSur.add(cmdCerrar); this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH); jPanel1.add(lblFecha, java.awt.BorderLayout.EAST); jPanel1.add(jLabel1, java.awt.BorderLayout.WEST); pnlNorte.add(jPanel2, java.awt.BorderLayout.EAST); jPanel2.add(jLabel2); jPanel2.add(lblTotal); this.setDefaultCloseOperation(DISPOSE_ON_CLOSE); }
public TablePane(int width, int height) { super(); setSize(new Dimension(width, height)); setLayout(new BorderLayout(10, 10)); myTable = new JTable(); tableModel = new DefaultTableModel(); JScrollPane scrollPane = new JScrollPane(myTable); // scrollPane.setVerticalScrollBarPolicy( JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED ); myTable.setFillsViewportHeight(true); add(scrollPane, BorderLayout.CENTER); setBorder(new EmptyBorder(20, 20, 20, 20)); myTable.setModel(tableModel); }
public static void main(String[] args) { PropertyTableModel model = new PropertyTableModel(System.getProperties()); JTable table = new JTable(); table.setModel(model); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JScrollPane spane = new JScrollPane(table); JFrame frame = new JFrame("System Properties"); frame.getContentPane().add(spane); frame.pack(); frame.setVisible(true); frame.addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent e) { System.exit(0); }; }); }
private void showChannels() { try { final double lat = Double.parseDouble(channelsLatTextField.getText()); final double lon = Double.parseDouble(channelsLonTextField.getText()); final double radius = Double.parseDouble(channelsRadiusTextField.getText()); availableChannels = Geo2TagService.loadAvailableChannelsAsList(authToken, lat, lon, radius); channelsTable.setModel( new AbstractTableModel() { public int getRowCount() { return availableChannels.size(); } public int getColumnCount() { return 2; } @Override public String getColumnName(final int column) { switch (column) { case 0: return "Name"; case 1: return "Description"; } return null; } public Object getValueAt(final int rowIndex, final int columnIndex) { final Channel channel = availableChannels.get(rowIndex); switch (columnIndex) { case 0: return channel.getName(); case 1: return channel.getDescription(); } return null; } }); channelsStatusBarLabel.setText(""); } catch (final Exception e) { channelsStatusBarLabel.setText("Error: " + e.getMessage()); System.out.println("Error: " + e); e.printStackTrace(); } }
private void backBind() { status.setText(viewModel.getStatus()); compute.setEnabled(viewModel.isButtonEnabled()); monthlyPayment.setText(viewModel.getMonthlyPayment()); overpaymentWithFees.setText(viewModel.getOverpaymentWithFees()); overpayment.setText(viewModel.getOverpayment()); DefaultTableModel model = viewModel.getGraphicOfPayments(); graphicOfPayments.setModel(model); graphicOfPayments.setPreferredSize( new Dimension( graphicOfPayments.getWidth(), graphicOfPayments.getRowHeight() * model.getRowCount())); List<String> log = viewModel.getLog(); String[] items = log.toArray(new String[log.size()]); logList.setListData(items); }
/** Initial method to populate the insuranceCompaniesTable */ public void loadTable() { Map<Integer, InsuranceCompany> data = model.getInsuranceCompanies(); tableData = new InsuranceCompanyTableModel(data); insuranceCompaniesTable.setModel(tableData); insuranceCompaniesTable.getColumnModel().getColumn(0).setMaxWidth(50); insuranceCompaniesTable .getSelectionModel() .setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // Check if db is empty and proceed with selecting only if the table is populated if (insuranceCompaniesTable.getRowCount() > 0) { // Set selected company according to selected row on load selectRow(); int selectedCompanyId = Integer.valueOf( (String) insuranceCompaniesTable.getValueAt(insuranceCompaniesTable.getSelectedRow(), 0)); } }
private void showSubscribedChannels() { try { subscribedChannels = Geo2TagService.loadSubscribedChannelsAsList(authToken); subscribedTable.setModel( new AbstractTableModel() { public int getRowCount() { return subscribedChannels.size(); } public int getColumnCount() { return 2; } @Override public String getColumnName(final int column) { switch (column) { case 0: return "Name"; case 1: return "Description"; } return null; } public Object getValueAt(final int rowIndex, final int columnIndex) { final Channel channel = subscribedChannels.get(rowIndex); switch (columnIndex) { case 0: return channel.getName(); case 1: return channel.getDescription(); } return null; } }); subscribedStatusBarLabel.setText(""); } catch (final Exception e) { subscribedStatusBarLabel.setText("Error: " + e.getMessage()); System.out.println("Error: " + e); e.printStackTrace(); } }
/** * Overriden to register a listener on the model. This listener ensures editing is cancelled when * editing row is being changed. * * @throws IllegalArgumentException if dataModel is not a {@link PropertySheetTableModel} * @see javax.swing.JTable#setModel(javax.swing.table.TableModel) */ public void setModel(TableModel newModel) { if (!(newModel instanceof PropertySheetTableModel)) { throw new IllegalArgumentException( "dataModel must be of type " + PropertySheetTableModel.class.getName()); } if (cancelEditing == null) { cancelEditing = new CancelEditing(); } TableModel oldModel = getModel(); if (oldModel != null) { oldModel.removeTableModelListener(cancelEditing); } super.setModel(newModel); newModel.addTableModelListener(cancelEditing); // ensure the "value" column can not be resized getColumnModel().getColumn(1).setResizable(false); }
@NotNull private static MyModel setTableModel( @NotNull JTable table, @NotNull UsageViewImpl usageView, @NotNull final List<UsageNode> data) { ApplicationManager.getApplication().assertIsDispatchThread(); final int columnCount = calcColumnCount(data); MyModel model = table.getModel() instanceof MyModel ? (MyModel) table.getModel() : null; if (model == null || model.getColumnCount() != columnCount) { model = new MyModel(data, columnCount); table.setModel(model); ShowUsagesTableCellRenderer renderer = new ShowUsagesTableCellRenderer(usageView); for (int i = 0; i < table.getColumnModel().getColumnCount(); i++) { TableColumn column = table.getColumnModel().getColumn(i); column.setCellRenderer(renderer); } } return model; }