List of usage examples for javax.swing.table TableColumn getModelIndex
public int getModelIndex()
From source file:org.yccheok.jstock.gui.JTableUtilities.java
public static int getModelColumnIndex(JTable jTable, Object value) { TableModel tableModel = jTable.getModel(); if (tableModel instanceof StockTableModel) { return ((StockTableModel) tableModel).findColumn(value.toString()); }/* w w w . j a v a2s.c om*/ try { TableColumn tableColumn = jTable.getColumn(value); return tableColumn.getModelIndex(); } // Anti-pattern. We are depending on the exception throwing. Bad! catch (java.lang.IllegalArgumentException exp) { final int columnCount = tableModel.getColumnCount(); for (int col = 0; col < columnCount; col++) { String s = tableModel.getColumnName(col); if (s.equals(value)) return col; } } return -1; }
From source file:put.semantic.fcanew.ui.MainWindow.java
private void continueStart() { final List<Attribute> forced = getAttributes(2); if (forced.isEmpty()) { forced.addAll(getAttributes(1)); }//from w ww .j a va2 s. co m logger.trace("START"); for (Attribute a : getUsedAttributes()) { logger.trace("ATTR: {}", a); } context = new PartialContext(new SimpleSetOfAttributes(getUsedAttributes()), kb); context.addProgressListener(progressListener); context.updateContext(); contextTable.setRowSorter(new TableRowSorter<>()); contextTable.setModel(new ContextDataModel(context)); contextTable.setDefaultRenderer(Object.class, new PODCellRenderer(kb.getReasoner())); Enumeration<TableColumn> e = contextTable.getColumnModel().getColumns(); JComboBox comboBox = new JComboBox(new Object[] { "+", "-", " " }); while (e.hasMoreElements()) { TableColumn col = e.nextElement(); col.setHeaderRenderer(new VerticalTableHeaderCellRenderer()); col.setCellEditor(new DefaultCellEditor(comboBox)); if (col.getModelIndex() >= 1) { col.setPreferredWidth(20); } } List<? extends FeatureCalculator> calculators = availableCalculatorsModel.getChecked(); for (FeatureCalculator calc : calculators) { if (calc instanceof EndpointCalculator) { ((EndpointCalculator) calc).setMappings(mappingsPanel1.getMappings()); } } Classifier classifier = (Classifier) classifierToUse.getSelectedItem(); classifier.setRejectedWeight((Double) rejectedWeight.getValue()); mlExpert = new MLExpert(classifier, (Integer) credibilityTreshold.getValue(), calculators, getIgnoreTreshold(), context, getAutoAcceptTreshold()); mlExpert.addEventListener(new MLExpertEventListener() { @Override public void implicationAccepted(ImplicationDescription i, boolean autoDecision) { logger.trace("ACCEPT"); setButtonsEnabled(false); ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.ACCEPT); registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.ACCEPT); } @Override public void implicationRejected(ImplicationDescription i, boolean autoDecision) { logger.trace("REJECT"); setButtonsEnabled(false); ((ConfusionMatrix) confusionMatrix.getModel()).add(i.getSuggestion(), Expert.Decision.REJECT); registerImplication(i.getImplication(), i.getClassificationOutcome(), Expert.Decision.REJECT); } private TableModel getFeaturesTableModel(Map<String, Double> features) { DefaultTableModel model = new DefaultTableModel(new String[] { "feature", "value" }, 0); for (Map.Entry<String, Double> f : features.entrySet()) { model.addRow(new Object[] { f.getKey(), f.getValue() }); } return model; } @Override public void ask(ImplicationDescription i, String justification) { logger.trace("ASK: {}", i.getImplication()); highlightButton(i.getSuggestion()); ((ContextDataModel) contextTable.getModel()).setCurrentImplication(i.getImplication()); justificationText.setText(justification); implicationText.setText(String.format("<html>%s</html>", i.getImplication().toString())); { Map<String, String> desc = i.getImplication().describe(kb); String s = "<html><table border=\"1\">"; s += "<tr><th>Attribute</th><th>Label</th></tr>"; for (Map.Entry<String, String> e : desc.entrySet()) { s += String.format("<tr><td>%s</td><td><pre>%s</pre></td></tr>", e.getKey(), e.getValue()); } s += "</table></html>"; implicationText.setToolTipText(s); } setButtonsEnabled(true); featuresTable.setModel(getFeaturesTableModel(i.getFeatures())); } }); learningExamplesTable.setModel(classifier.getExamplesTableModel()); fca = new FCA(); fca.setContext(context); fca.setExpert(mlExpert); new SwingWorker() { @Override protected Object doInBackground() throws Exception { fca.reset(forced); fca.run(); return null; } @Override protected void done() { try { get(); logger.trace("FINISHED"); if (script != null) { String name = JOptionPane.showInputDialog(MainWindow.this, "Jeeli chcesz otrzyma punkty z TSiSS, podaj swoje imi, nazwisko i nr indeksu", "TSiSS", JOptionPane.QUESTION_MESSAGE); if (name != null) { logger.trace("NAME: {}", name); } script.submitLog(new File("fca.log")); } implicationText.setText("Bye-bye"); } catch (InterruptedException | ExecutionException ex) { implicationText.setText(ex.getLocalizedMessage()); ex.printStackTrace(); } } }.execute(); }
From source file:ua.com.fielden.platform.example.swing.egi.EgiExample.java
private void addTotalsFooterTo(final EntityGridInspector egi, final JPanel topPanel) { // final JPanel panel = new JPanel(new MigLayout("insets 0", "[]", "[]0[]push[]")); // panel.add(egi.getTableHeader(), "grow, wrap"); // panel.add(egi, "grow, wrap"); final JScrollPane scrollPane = new JScrollPane(egi); topPanel.add(scrollPane, "grow, wrap"); final JPanel footer = new JPanel(new MigLayout("nogrid, insets 0")); // footer.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED)); final List<JComponent> totalsComponents = new ArrayList<JComponent>(); for (int i = 0; i < egi.getColumnCount(); i++) { final TableColumn column = egi.getColumnModel().getColumn(i); final JComponent totalsComponent = i % 2 == 0 ? new JTextField("totals " + i) : new JLabel(); totalsComponent.setPreferredSize(new Dimension(column.getPreferredWidth(), 30)); footer.add(totalsComponent, "grow"); totalsComponents.add(totalsComponent); }/*from ww w . j a va 2s . c om*/ final JScrollPane footerPane = new JScrollPane(footer, JScrollPane.VERTICAL_SCROLLBAR_NEVER, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); topPanel.add(footerPane, "grow, wrap, h 40::"); topPanel.add(scrollPane.getHorizontalScrollBar(), "grow, wrap"); scrollPane.getHorizontalScrollBar().addAdjustmentListener(new AdjustmentListener() { @Override public void adjustmentValueChanged(final AdjustmentEvent e) { footerPane.getViewport().setViewPosition(new Point(e.getValue(), 0)); } }); egi.getColumnModel().addColumnModelListener(new TableColumnModelListener() { @Override public void columnAdded(final TableColumnModelEvent e) { } @Override public void columnMarginChanged(final ChangeEvent e) { final TableColumn column = egi.getTableHeader().getResizingColumn(); if (column != null) { final JComponent totalsComponent = totalsComponents .get(egi.convertColumnIndexToView(column.getModelIndex())); totalsComponent.setPreferredSize(new Dimension(column.getWidth(), totalsComponent.getHeight())); footer.revalidate(); } } @Override public void columnMoved(final TableColumnModelEvent e) { final JComponent fromComponent = totalsComponents.get(e.getFromIndex()); totalsComponents.set(e.getFromIndex(), totalsComponents.get(e.getToIndex())); totalsComponents.set(e.getToIndex(), fromComponent); footer.removeAll(); for (int i = 0; i < egi.getColumnCount(); i++) { footer.add(totalsComponents.get(i), "grow, gap 0 0 0 0"); } footer.revalidate(); } @Override public void columnRemoved(final TableColumnModelEvent e) { } @Override public void columnSelectionChanged(final ListSelectionEvent e) { } }); // // return panel; }