List of usage examples for javax.swing.event ListSelectionListener ListSelectionListener
ListSelectionListener
From source file:edu.ku.brc.specify.utilapps.sp5utils.Sp5Forms.java
/** * /*w w w . j a v a2 s. c o m*/ */ protected void createUI() { CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,p,p:g", "p,2px,f:p:g,4px,p,2px,p,10px,p")); missingFieldsList = new JList(new DefaultListModel()); formsTable = new JTable(new FormCellModel(forms)); formsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (formsTable.getSelectedRow() > -1) { formSelected(); } } }); fieldsTable = new JTable(fieldsTableModel = new FieldCellModel()); TableColumn col = fieldsTable.getColumnModel().getColumn(1); col.setCellEditor(sp6FieldEditor = new Sp6FieldComboBoxEditor()); // If the cell should appear like a combobox in its // non-editing state, also set the combobox renderer //col.setCellRenderer(sp6FieldRenderer = new Sp6FieldComboBoxRenderer()); calcColumnWidths(formsTable); PanelBuilder pbBtn = new PanelBuilder(new FormLayout("f:p:g,p,f:p:g,p,f:p:g,p,f:p:g,p,f:p:g", "p")); reportBtn = createButton("Create Form Images"); showBtn = createButton("Show"); schemaBtn = createButton("Schema"); dataCheckerBtn = createButton("Check For Nulls"); pbBtn.add(reportBtn, cc.xy(2, 1)); pbBtn.add(schemaBtn, cc.xy(4, 1)); pbBtn.add(showBtn, cc.xy(6, 1)); pbBtn.add(dataCheckerBtn, cc.xy(8, 1)); pb.add(createLabel("Forms", SwingConstants.CENTER), cc.xy(1, 1)); pb.add(createLabel("Missing Fields", SwingConstants.CENTER), cc.xy(3, 1)); pb.add(createScrollPane(formsTable), cc.xy(1, 3)); pb.add(createScrollPane(missingFieldsList), cc.xy(3, 3)); pb.add(createLabel("Form Fields", SwingConstants.CENTER), cc.xyw(1, 5, 3)); pb.add(createScrollPane(fieldsTable), cc.xyw(1, 7, 3)); pb.add(pbBtn.getPanel(), cc.xyw(1, 9, 3)); pb.setDefaultDialogBorder(); setContentPane(new JScrollPane(pb.getPanel())); showBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { showForm(); } }); reportBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doCreateFormImages(); } }); schemaBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { doSchema(); } }); dataCheckerBtn.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { TableDataChecker tdc = new TableDataChecker(DBConnection.getInstance().createConnection()); tdc.doCheckDB(); } }); }
From source file:edu.ku.brc.specify.plugins.CollectionRelPlugin.java
@Override public void initialize(final Properties propertiesArg, final boolean isViewModeArg) { super.initialize(propertiesArg, isViewModeArg); String relName = propertiesArg.getProperty("relname"); String rightSide = propertiesArg.getProperty("rightside"); isRightOverride = StringUtils.isNotEmpty(rightSide) && rightSide.equalsIgnoreCase("true"); if (StringUtils.isNotEmpty(relName)) { DataProviderSessionIFace tmpSession = null; try {/* ww w . j a v a 2 s . c om*/ tmpSession = DataProviderFactory.getInstance().createSession(); colRelType = tmpSession.getData(CollectionRelType.class, "name", relName, DataProviderSessionIFace.CompareType.Equals); if (colRelType != null) { leftSideCol = colRelType.getLeftSideCollection(); rightSideCol = colRelType.getRightSideCollection(); //colRelType.getRelationships().size(); rightSideCol.getCollectionId(); leftSideCol.getCollectionId(); Collection currCollection = AppContextMgr.getInstance().getClassObject(Collection.class); isLeftSide = currCollection.getId().equals(leftSideCol.getId()); if (isLeftSide && isRightOverride) { isLeftSide = false; } catNumFormatter = CollectionRelOneToManyPlugin.getCatNumFormatter(leftSideCol, rightSideCol); } else { DBTableInfo ti = DBTableIdMgr.getInstance() .getInfoById(CollectionRelationship.getClassTableId()); UIRegistry.showError( String.format("The %s name '%s' doesn't exist (defined in the form for the plugin).", ti.getTitle(), relName)); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (tmpSession != null) { tmpSession.close(); } } DBTableInfo coTI = DBTableIdMgr.getInstance().getInfoById(CollectionObject.getClassTableId()); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("MAX(p;40px)", "p"), this); if (isViewModeArg || !isLeftSide) { textWithInfo = new TextFieldWithInfo(coTI.getClassName(), CATNUM_NAME, // id name CATNUM_NAME, // key name null, // format CATNUM_NAMECAP, // uiFieldFormatterName COLOBJ_NAME, // dataObjFormatterName COLOBJ_NAME, // displayInfoDialogName ""); // objTitle pb.add(textWithInfo, cc.xy(1, 1)); ViewFactory.changeTextFieldUIForDisplay(textWithInfo.getTextField(), false); } else { int btnOpts = ValComboBoxFromQuery.CREATE_VIEW_BTN | ValComboBoxFromQuery.CREATE_SEARCH_BTN; cbx = new ValComboBoxFromQuery(coTI, CATNUM_NAME, CATNUM_NAME, CATNUM_NAME, null, CATNUM_NAMECAP, COLOBJ_NAME, "", null, // helpContext btnOpts); pb.add(cbx, cc.xy(1, 1)); cbx.setEnabled(colRelType != null); adjustSQLTemplate(); cbx.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { itemSelected(); notifyChangeListeners(new ChangeEvent(CollectionRelPlugin.this)); } }); cbx.registerQueryBuilder(createSearchQueryBuilder(isLeftSide, leftSideCol, rightSideCol)); } } else { // no Relationship name } }
From source file:captureplugin.drivers.defaultdriver.AdditionalParams.java
/** * Create List-Panel//from www.j ava 2 s . com * @return List-Panel */ private Component createListPanel() { JPanel panel = new JPanel(new BorderLayout(0, 2)); panel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); panel.add(new JLabel(mLocalizer.msg("command", "Command")), BorderLayout.NORTH); mList = new JList(mListModel); panel.add(new JScrollPane(mList), BorderLayout.CENTER); JPanel buttons = new JPanel(new FlowLayout(FlowLayout.LEFT)); JButton add = new JButton(TVBrowserIcons.newIcon(TVBrowserIcons.SIZE_SMALL)); add.setToolTipText(Localizer.getLocalization(Localizer.I18N_ADD)); add.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { addPressed(); } }); buttons.add(add); JButton remove = new JButton(TVBrowserIcons.delete(TVBrowserIcons.SIZE_SMALL)); remove.setToolTipText(Localizer.getLocalization(Localizer.I18N_DELETE)); remove.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { removePressed(); } }); buttons.add(remove); final JButton up = new JButton(TVBrowserIcons.up(TVBrowserIcons.SIZE_SMALL)); up.setToolTipText(Localizer.getLocalization(Localizer.I18N_UP)); buttons.add(up); up.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { upPressed(); } }); final JButton down = new JButton(TVBrowserIcons.down(TVBrowserIcons.SIZE_SMALL)); down.setToolTipText(Localizer.getLocalization(Localizer.I18N_DOWN)); buttons.add(down); down.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { downPressed(); } }); mStartStop = new JButton(mStartIcon); mStartStop.setToolTipText(mLocalizer.msg("startstop", "Activate or Deactivate Parameter")); mStartStop.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { startStopPressed(); } }); buttons.add(mStartStop); panel.add(buttons, BorderLayout.SOUTH); mList.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { selectionChanged(); if (mList.getSelectedIndex() == 0) { up.setEnabled(false); down.setEnabled(true); } else if (mList.getSelectedIndex() == mListModel.getSize() - 1) { up.setEnabled(true); down.setEnabled(false); } else { up.setEnabled(true); down.setEnabled(true); } } }); selectionChanged(); return panel; }
From source file:TopLevelTransferHandlerDemo.java
public TopLevelTransferHandlerDemo() { super("TopLevelTransferHandlerDemo"); setJMenuBar(createDummyMenuBar());// ww w .ja va 2 s. c o m getContentPane().add(createDummyToolBar(), BorderLayout.NORTH); JSplitPane sp = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, list, dp); sp.setDividerLocation(120); getContentPane().add(sp); //new Doc("sample.txt"); //new Doc("sample.txt"); //new Doc("sample.txt"); list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { if (e.getValueIsAdjusting()) { return; } Doc val = (Doc) list.getSelectedValue(); if (val != null) { val.select(); } } }); final TransferHandler th = list.getTransferHandler(); nullItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (nullItem.isSelected()) { list.setTransferHandler(null); } else { list.setTransferHandler(th); } } }); thItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if (thItem.isSelected()) { setTransferHandler(handler); } else { setTransferHandler(null); } } }); dp.setTransferHandler(handler); }
From source file:edu.ku.brc.specify.plugins.CollectionRelOneToManyPlugin.java
@Override public void initialize(Properties propertiesArg, boolean isViewModeArg) { super.initialize(propertiesArg, isViewModeArg); String relName = propertiesArg.getProperty("relname"); if (StringUtils.isNotEmpty(relName)) { DataProviderSessionIFace tmpSession = null; try {/*from www . java2s.c o m*/ tmpSession = DataProviderFactory.getInstance().createSession(); colRelType = tmpSession.getData(CollectionRelType.class, "name", relName, DataProviderSessionIFace.CompareType.Equals); if (colRelType != null) { leftSideCol = colRelType.getLeftSideCollection(); rightSideCol = colRelType.getRightSideCollection(); rightSideCol.getCollectionId(); leftSideCol.getCollectionId(); catNumFormatter = getCatNumFormatter(leftSideCol, rightSideCol); Collection currCollection = AppContextMgr.getInstance().getClassObject(Collection.class); isLeftSide = currCollection.getId().equals(leftSideCol.getId()); if (!isLeftSide) { // major error } } else { DBTableInfo ti = DBTableIdMgr.getInstance() .getInfoById(CollectionRelationship.getClassTableId()); UIRegistry.showError( String.format("The %s name '%s' doesn't exist (defined in the form for the plugin).", ti.getTitle(), relName)); } } catch (Exception ex) { ex.printStackTrace(); } finally { if (tmpSession != null) { tmpSession.close(); } } CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(new FormLayout("f:p:g,2px,p", "f:p:g"), this); model = new ColObjDataModel(); table = new JTable(model); JScrollPane sp = UIHelper.createScrollPane(table, false); pb.add(sp, cc.xy(1, 1)); searchAddBtn = UIHelper.createIconBtn("SearchAdd", IconManager.IconSize.Std20, "", true, createSearchAL()); removeBtn = UIHelper.createIconBtn("Eraser", IconManager.IconSize.NonStd, "", true, createRemoveAL()); infoBtn = UIHelper.createIconBtn("InfoIcon", IconManager.IconSize.Std20, "", true, createInfoAL()); PanelBuilder rpb = new PanelBuilder(new FormLayout("f:p:g", "p,4px,p,4px,p, f:p:g")); int y = 1; rpb.add(infoBtn, cc.xy(1, y)); y += 2; if (!isViewMode) { rpb.add(searchAddBtn, cc.xy(1, y)); y += 2; rpb.add(removeBtn, cc.xy(1, y)); y += 2; } pb.add(rpb.getPanel(), cc.xy(3, 1)); UIHelper.makeTableHeadersCentered(table, true); UIHelper.setVisibleRowCount(table, 5); table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); table.setCellSelectionEnabled(false); table.setColumnSelectionAllowed(false); table.setRowSelectionAllowed(true); table.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateBtns(); } }); updateBtns(); } else { System.err.println(propertiesArg); log.error("CollectionRelOneToManyPlugin - initialize attribute for 'relname' is null and can't be!"); } }
From source file:com.mirth.connect.client.ui.editors.MapperPanel.java
public void setRegexProperties(ArrayList<String[]> properties) { Object[][] tableData = new Object[properties.size()][2]; regularExpressionsTable = new MirthTable(); for (int i = 0; i < properties.size(); i++) { tableData[i][REGEX_COLUMN] = properties.get(i)[0]; tableData[i][REPLACEWITH_COLUMN] = properties.get(i)[1]; }/*from www. j a v a 2 s. c om*/ regularExpressionsTable.setModel(new javax.swing.table.DefaultTableModel(tableData, new String[] { REGEX_COLUMN_NAME, REPLACEWITH_COLUMN_NAME }) { boolean[] canEdit = new boolean[] { true, true }; public boolean isCellEditable(int rowIndex, int columnIndex) { return canEdit[columnIndex]; } }); regularExpressionsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent evt) { if (getSelectedRow() != -1) { lastIndex = getSelectedRow(); deleteButton.setEnabled(true); } else { deleteButton.setEnabled(false); } } }); class RegExTableCellEditor extends TextFieldCellEditor { @Override public boolean isCellEditable(EventObject evt) { boolean editable = super.isCellEditable(evt); if (editable) { deleteButton.setEnabled(false); } return editable; } @Override protected boolean valueChanged(String value) { parent.modified = true; deleteButton.setEnabled(true); return true; } } regularExpressionsTable.getColumnModel() .getColumn(regularExpressionsTable.getColumnModel().getColumnIndex(REGEX_COLUMN_NAME)) .setCellEditor(new RegExTableCellEditor()); regularExpressionsTable.getColumnModel() .getColumn(regularExpressionsTable.getColumnModel().getColumnIndex(REPLACEWITH_COLUMN_NAME)) .setCellEditor(new RegExTableCellEditor()); regularExpressionsTable.setCustomEditorControls(true); regularExpressionsTable.setSelectionMode(0); regularExpressionsTable.setRowSelectionAllowed(true); regularExpressionsTable.setRowHeight(UIConstants.ROW_HEIGHT); regularExpressionsTable.setDragEnabled(false); regularExpressionsTable.setOpaque(true); regularExpressionsTable.setSortable(false); regularExpressionsTable.getTableHeader().setReorderingAllowed(false); if (Preferences.userNodeForPackage(Mirth.class).getBoolean("highlightRows", true)) { Highlighter highlighter = HighlighterFactory.createAlternateStriping(UIConstants.HIGHLIGHTER_COLOR, UIConstants.BACKGROUND_COLOR); regularExpressionsTable.setHighlighters(highlighter); } regularExpressionsScrollPane.setViewportView(regularExpressionsTable); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReportFrame.java
/** * Creates new form DSWorkbenchReportFrame *//*from w ww . j a va2s. co m*/ DSWorkbenchReportFrame() { initComponents(); centerPanel = new GenericTestPanel(); jReportsPanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jXReportsPanel); buildMenu(); capabilityInfoPanel1.addActionListener(this); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); ActionListener resultListener = new ActionListener() { @Override public void actionPerformed(ActionEvent e) { copyResultBBToClipboardEvent(); } }; capabilityInfoPanel2.addActionListener(resultListener); jResultTabbedPane.registerKeyboardAction(resultListener, "BBCopy", bbCopy, JComponent.WHEN_IN_FOCUSED_WINDOW); jReportsTabbedPane.getModel().addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { ReportTableTab activeTab = getActiveTab(); if (activeTab != null) { activeTab.updateSet(); } } }); jXColumnList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { updateFilter(); } }); jList1.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { fireRebuildStatsEvent(); } } }); setGlassPane(jxSearchPane); rulesDialog = new ReportRulesDialog(this, true); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.reports_view", GlobalOptions.getHelpBroker().getHelpSet()); GlobalOptions.getHelpBroker().enableHelpKey(jCreateStatsFrame.getRootPane(), "pages.reports_view_stats", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> jCreateStatsFrame.pack(); pack(); }
From source file:com.rapidminer.gui.plotter.charts.AbstractPieChartPlotter.java
public AbstractPieChartPlotter(final PlotterConfigurationModel settings) { super(settings); setBackground(Color.white);/*from w w w. ja va 2 s .c om*/ useDistinct = new ListeningJCheckBox("_" + PARAMETERS_USE_DISTINCT, "Use Only Distinct", false); useDistinct.setToolTipText("Indicates if only distinct values should be used for aggregation functions."); useDistinct.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { settings.setParameterAsBoolean(PARAMETERS_USE_DISTINCT, useDistinct.isSelected()); } }); String[] allFunctions = new String[AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length + 1]; allFunctions[0] = "none"; System.arraycopy(AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES, 0, allFunctions, 1, AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length); aggregationFunction = new ListeningJComboBox(settings, "_" + PARAMETERS_AGGREGATION, allFunctions); aggregationFunction.setToolTipText( "Select the type of the aggregation function which should be used for grouped values."); aggregationFunction.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { settings.setParameterAsString(PARAMETERS_AGGREGATION, aggregationFunction.getSelectedItem().toString()); } }); for (int i = 0; i < allFunctions.length; i++) { if (allFunctions[i].equals("count")) { aggregationFunction.setSelectedIndex(i); } } explodingGroupList = new ExtendedJList(new ExtendedListModel(), 200); explodingGroupListSelectionModel = new ListeningListSelectionModel("_" + PARAMETERS_EXPLOSION_GROUPS, explodingGroupList); explodingGroupList.setSelectionModel(explodingGroupListSelectionModel); explodingGroupList.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { Object[] values = explodingGroupList.getSelectedValues(); List<String> list = new LinkedList<String>(); for (Object object : values) { list.add((String) object); } String result = ParameterTypeEnumeration.transformEnumeration2String(list); settings.setParameterAsString(PARAMETERS_EXPLOSION_GROUPS, result); } } }); explodingGroupList.setForeground(Color.BLACK); explodingGroupList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); explodingGroupList.setBorder(BorderFactory.createLoweredBevelBorder()); explodingGroupList.setCellRenderer(new PlotterPanel.LineStyleCellRenderer(this)); updateGroups(); explodingSlider = new ListeningJSlider("_" + PARAMETERS_EXPLOSION_AMOUNT, 0, 100, 0); explodingSlider.addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { settings.setParameterAsInt(PARAMETERS_EXPLOSION_AMOUNT, explodingSlider.getValue()); } }); }
From source file:de.tor.tribes.ui.views.DSWorkbenchReTimerFrame.java
/** Creates new form DSWorkbenchReTimerFrame */ DSWorkbenchReTimerFrame() {//w w w . j av a 2s . c om initComponents(); centerPanel = new GenericTestPanel(true); jReTimePanel.add(centerPanel, BorderLayout.CENTER); centerPanel.setChildComponent(jideRetimeTabbedPane); jideRetimeTabbedPane.setTabShape(JideTabbedPane.SHAPE_OFFICE2003); jideRetimeTabbedPane.setTabColorProvider(JideTabbedPane.ONENOTE_COLOR_PROVIDER); jideRetimeTabbedPane.setBoldActiveTab(true); jideRetimeTabbedPane.addTab("Festlegen des Angriffs", jInputPanel); jideRetimeTabbedPane.addTab("Errechnete Gegenangriffe", jResultPanel); buildMenu(); capabilityInfoPanel1.addActionListener(this); KeyStroke copy = KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK, false); KeyStroke bbCopy = KeyStroke.getKeyStroke(KeyEvent.VK_B, ActionEvent.CTRL_MASK, false); KeyStroke delete = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false); KeyStroke cut = KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK, false); jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Copy", copy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "BBCopy", bbCopy, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Delete", delete, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jResultTable.registerKeyboardAction(DSWorkbenchReTimerFrame.this, "Cut", cut, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); jResultTable.getActionMap().put("find", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { //ignore find } }); jCommandArea.setPrompt("<Angriffsbefehl hier einfgen>"); jResultTable.getSelectionModel().addListSelectionListener(DSWorkbenchReTimerFrame.this); jPossibleUnits.setCellRenderer(new UnitListCellRenderer()); jPossibleUnits.addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { updateAttackBBView(); } } }); // <editor-fold defaultstate="collapsed" desc=" Init HelpSystem "> if (!Constants.DEBUG) { GlobalOptions.getHelpBroker().enableHelpKey(getRootPane(), "pages.retime_tool", GlobalOptions.getHelpBroker().getHelpSet()); } // </editor-fold> }
From source file:org.angnysa.yaba.swing.BudgetFrame.java
private void buildReconciliationTable() { reconciliationModel = new ReconciliationTableModel(service); reconciliationTable = new JTable(reconciliationModel); reconciliationTable.setRowHeight((int) (reconciliationTable.getRowHeight() * 1.2)); reconciliationTable.setDefaultEditor(LocalDate.class, new CustomCellEditor(new JFormattedTextField(new JodaLocalDateFormat()))); reconciliationTable.setDefaultEditor(Double.class, new CustomCellEditor(new JFormattedTextField(NumberFormat.getNumberInstance()))); reconciliationTable.setDefaultRenderer(LocalDate.class, new FormattedTableCellRenderer(new JodaLocalDateFormat())); reconciliationTable.setDefaultRenderer(Double.class, new FormattedTableCellRenderer(TransactionAmountFormatFactory.getFormat())); reconciliationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); reconciliationTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "delete"); //$NON-NLS-1$ reconciliationTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT) .put(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, 0), "delete"); //$NON-NLS-1$ reconciliationTable.getActionMap().put("delete", new AbstractAction() { //$NON-NLS-1$ private static final long serialVersionUID = 1L; @Override/*from w w w .j a v a2 s .c o m*/ public void actionPerformed(ActionEvent e) { int row = reconciliationTable.getSelectedRow(); if (row >= 0) { reconciliationModel.deleteRow(row); } } }); transactionTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override public void valueChanged(ListSelectionEvent e) { if (!e.getValueIsAdjusting()) { int row = transactionTable.getSelectedRow(); if (row >= 0) { row = transactionTable.getRowSorter().convertRowIndexToModel(row); TransactionDefinition td = transactionModel.getTransactionForRow(row); if (td != null) { reconciliationModel.setCurrentTransactionId(td.getId()); } else { reconciliationModel.setCurrentTransactionId(-1); } } else { reconciliationModel.setCurrentTransactionId(-1); } } } }); }