List of usage examples for javax.swing.event TableModelEvent getFirstRow
public int getFirstRow()
From source file:Main.java
public void tableChanged(TableModelEvent e) { int firstRow = e.getFirstRow(); int lastRow = e.getLastRow(); int index = e.getColumn(); switch (e.getType()) { case TableModelEvent.INSERT: for (int i = firstRow; i <= lastRow; i++) { System.out.println(i); }//from www.ja v a2s.c om break; case TableModelEvent.UPDATE: if (firstRow == TableModelEvent.HEADER_ROW) { if (index == TableModelEvent.ALL_COLUMNS) { System.out.println("A column was added"); } else { System.out.println(index + "in header changed"); } } else { for (int i = firstRow; i <= lastRow; i++) { if (index == TableModelEvent.ALL_COLUMNS) { System.out.println("All columns have changed"); } else { System.out.println(index); } } } break; case TableModelEvent.DELETE: for (int i = firstRow; i <= lastRow; i++) { System.out.println(i); } break; } }
From source file:Main.java
Main() { JFrame jfrm = new JFrame("JTable Event Demo"); jfrm.setSize(400, 200);/*from w w w .j av a2s .c om*/ jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jtabOrders.setPreferredScrollableViewportSize(new Dimension(420, 62)); ListSelectionModel rowSelMod = jtabOrders.getSelectionModel(); ListSelectionModel colSelMod = jtabOrders.getColumnModel().getSelectionModel(); rowSelMod.addListSelectionListener(this); colSelMod.addListSelectionListener(this); tm = jtabOrders.getModel(); tm.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent tme) { if (tme.getType() == TableModelEvent.UPDATE) { System.out.println("Cell " + tme.getFirstRow() + ", " + tme.getColumn() + " changed." + " The new value: " + tm.getValueAt(tme.getFirstRow(), tme.getColumn())); } } }); jfrm.add(new JScrollPane(jtabOrders)); jfrm.setVisible(true); }
From source file:gui.accessories.BattleSimFx.java
private BarChart createBarChart() { CategoryAxis xAxis = new CategoryAxis(); xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames())); xAxis.setLabel("Year"); double tickUnit = tableModel.getTickUnit(); NumberAxis yAxis = new NumberAxis(); yAxis.setTickUnit(tickUnit);//from ww w .j a v a 2s .co m yAxis.setLabel("Units Sold"); final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData()); tableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { final int row = e.getFirstRow(); final int column = e.getColumn(); final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column); Platform.runLater(new Runnable() { @Override public void run() { XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData() .get(row); BarChart.Data data = s.getData().get(column); data.setYValue(value); } }); } } }); return aChart; }
From source file:gui.accessories.GraphPopup.java
private BarChart createBarChartDynamic() { SampleTableModel tableModel = new SampleTableModel(); CategoryAxis xAxis = new CategoryAxis(); xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames())); xAxis.setLabel("Year"); double tickUnit = tableModel.getTickUnit(); NumberAxis yAxis = new NumberAxis(); yAxis.setTickUnit(tickUnit);/*from w ww . j ava 2 s . c o m*/ yAxis.setLabel("Units Sold"); final BarChart aChart = new BarChart(xAxis, yAxis, tableModel.getBarChartData()); aChart.setAnimated(true); tableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { final int row = e.getFirstRow(); final int column = e.getColumn(); final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column); Platform.runLater(new Runnable() { @Override public void run() { XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) aChart.getData() .get(row); BarChart.Data data = s.getData().get(column); data.setYValue(value); } }); } } }); return aChart; }
From source file:SampleTableModel.java
private BarChart createBarChart() { CategoryAxis xAxis = new CategoryAxis(); xAxis.setCategories(FXCollections.<String>observableArrayList(tableModel.getColumnNames())); xAxis.setLabel("Year"); double tickUnit = tableModel.getTickUnit(); NumberAxis yAxis = new NumberAxis(); yAxis.setTickUnit(tickUnit);// ww w . j a va 2 s.co m yAxis.setLabel("Units Sold"); final BarChart chart = new BarChart(xAxis, yAxis, tableModel.getBarChartData()); tableModel.addTableModelListener(new TableModelListener() { public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { final int row = e.getFirstRow(); final int column = e.getColumn(); final Object value = ((SampleTableModel) e.getSource()).getValueAt(row, column); Platform.runLater(new Runnable() { public void run() { XYChart.Series<String, Number> s = (XYChart.Series<String, Number>) chart.getData() .get(row); BarChart.Data data = s.getData().get(column); data.setYValue(value); } }); } } }); return chart; }
From source file:MainFrame.MainFrame.java
public MainFrame() { //Create menu this.menuBar = new JMenuBar(); this.menuProxy = new JMenu("Proxy"); this.menuBar.add(menuProxy); this.cbMenuItem = new JCheckBoxMenuItem("? proxy"); this.cbMenuItem.setMnemonic(KeyEvent.VK_C); ActionListener aListener = new ActionListener() { public void actionPerformed(ActionEvent event) { AbstractButton aButton = (AbstractButton) event.getSource(); boolean selected = aButton.getModel().isSelected(); if (selected) { SingleDataHolder.getInstance().isProxyActivated = true; SingleDataHolder.getInstance().proxyIpAdress = MainFrame.this.proxyIpAdress.getText(); SingleDataHolder.getInstance().proxyPort = Integer.parseInt(MainFrame.this.proxyPort.getText()); SingleDataHolder.getInstance().proxyLogin = MainFrame.this.proxyLogin.getText(); SingleDataHolder.getInstance().proxyPassword = String .valueOf(MainFrame.this.proxyPassword.getPassword()); } else { SingleDataHolder.getInstance().isProxyActivated = false; }// ww w.j a va2 s. c o m } }; this.cbMenuItem.addActionListener(aListener); this.proxyIpAdress = new JTextField(); this.proxyPort = new JTextField(); this.proxyLogin = new JTextField(); ; this.proxyPassword = new JPasswordField(); this.menuProxy.add(this.cbMenuItem); this.menuProxy.add(new JLabel("IP ?")); this.menuProxy.add(this.proxyIpAdress); this.menuProxy.add(new JLabel("? ")); this.menuProxy.add(this.proxyPort); this.menuProxy.add(new JLabel("")); this.menuProxy.add(this.proxyLogin); this.menuProxy.add(new JLabel("")); this.menuProxy.add(this.proxyPassword); this.setJMenuBar(this.menuBar); communicator = new HttpCommunicator(); myActionListener = new mainFrameActionListener(); mainPanel = new JPanel(new BorderLayout()); this.setContentPane(mainPanel); JPanel P = new JPanel(new FlowLayout(FlowLayout.LEFT, 15, 5)); mainPanel.add(P, BorderLayout.NORTH); //Create Group label labelGroup = new JLabel(""); P.add(labelGroup); //Create Group combo comboGroup = new JComboBox(); comboGroup.addItem("?"); comboGroup.addActionListener(myActionListener); P.add(comboGroup); //Create Date label labelDate = new JLabel(""); P.add(labelDate); //Create Date combo comboDate = new JComboBox(); comboDate.addItem("?"); comboDate.addActionListener(myActionListener); P.add(comboDate); //Create Delete button buttonDelete = new JButton(""); buttonDelete.setEnabled(false); buttonDelete.addActionListener(myActionListener); P.add(buttonDelete); //this.checkConnection = new CheckConnection(buttonDelete); buttonPasswordsManager = new JButton(" "); buttonPasswordsManager.addActionListener(myActionListener); P.add(buttonPasswordsManager); try { Image img = ImageIO.read(getClass().getResource("resources/table_refresh.png")); this.buttonRefresh = new JButton(new ImageIcon(img)); this.buttonRefresh.addActionListener(myActionListener); this.buttonRefresh.setToolTipText(" "); P.add(buttonRefresh); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } //CreateLessonTableModel lessonTableModel = new LessonTableModel(); try { communicator.setCombos(comboGroup, comboDate, lessonTableModel); } catch (IOException ex) { JOptionPane.showMessageDialog(null, " ? ? ."); Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } //CreateTable table = new JTable(lessonTableModel); table.setFillsViewportHeight(true); table.setAutoCreateRowSorter(true); JScrollPane scrollP = new JScrollPane(table); mainPanel.add(scrollP, BorderLayout.CENTER); //Create Table sorter sorter = new TableRowSorter<LessonTableModel>(lessonTableModel); table.setRowSorter(sorter); table.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int column = e.getColumn(); TableModel model = (TableModel) e.getSource(); for (int i = 0; i < model.getRowCount(); i++) { if ((boolean) model.getValueAt(i, 2) == true) { buttonDelete.setEnabled(true); return; } } buttonDelete.setEnabled(false); } }); //Standart block this.setSize(700, 400); this.setTitle(" "); this.addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent we) { System.exit(0); } }); try { Image img = ImageIO.read(getClass().getResource("resources/appIcon.png")); this.setIconImage(img); } catch (IOException ex) { Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, null, ex); } this.setVisible(true); }
From source file:edu.ku.brc.af.ui.forms.formatters.DataObjFieldFormatMultiplePanel.java
/** * @param model/* ww w . ja v a 2s . co m*/ */ protected void addTableModelListener(DefaultTableModel model) { TableModelListener tml = new TableModelListener() { public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int column = e.getColumn(); DefaultTableModel localModel = (DefaultTableModel) e.getSource(); String columnName = localModel.getColumnName(column); if (columnName.equals(FIELD_VALUE_COL)) { int formatColumn = formatSwitchTbl.getColumnModel().getColumnIndex(DISPLAY_FORMAT_COL); DataObjDataFieldFormat format = (DataObjDataFieldFormat) localModel.getValueAt(row, formatColumn); String value = (String) localModel.getValueAt(row, column); format.setValue(value); enableUIControls(); } } }; model.addTableModelListener(tml); }
From source file:org.jdal.swing.TableEditor.java
@SuppressWarnings("unchecked") public void tableChanged(TableModelEvent e) { if (e.getType() == TableModelEvent.UPDATE) { int row = e.getFirstRow(); if (row >= 0) { dirtyModels.add((T) tableModel.getList().get(row)); }// w w w . j av a 2 s . c o m } }
From source file:com.jskj.asset.client.panel.slgl.DiZhiYiHaoPinLingYongTuiKuJDialog.java
/** * Creates new form GuDingZiChanRuKu/*from www . j a va2 s.co m*/ */ public DiZhiYiHaoPinLingYongTuiKuJDialog() { super(); initComponents(); zc = new ArrayList<ZiChanLieBiaotb>(); userId = AssetClientApp.getSessionMap().getUsertb().getUserId(); userName = AssetClientApp.getSessionMap().getUsertb().getUserName(); department = AssetClientApp.getSessionMap().getDepartment().getDepartmentName(); kucunmap = new HashMap(); jTextFieldShenqingren.setText(userName); jTextFieldDept.setText(department); jTextField1.setText(DanHao.getDanHao("YHTK")); jTextField1.setEditable(false); jTextField2.setText(dateformate.format(new Date()).toString()); jTextField2.setEditable(false); final BaseTable.SingleEditRowTable editTable = ((BaseTable) jTable1).createSingleEditModel( new String[][] { { "dzyhpId", "??" }, { "dzyhpName", "???", "true" }, { "dzyhpType", "?" }, { "dzyhpPinpai", "?", "false" }, { "dzyhpXinghao", "?" }, { "unitId", "??", "false" }, { "quantity", "?", "true" }, { "lylb.price", "", "false" }, { "total", "?" }, { "lylb.pihao", "??", "false" } }); editTable.registerPopup(1, new IPopupBuilder() { @Override public int getType() { return IPopupBuilder.TYPE_POPUP_TABLE; } @Override public String getWebServiceURI() { return Constants.HTTP + Constants.APPID + "dizhiyihaopin/findtk"; } @Override public String getConditionSQL() { int selectedColumn = jTable1.getSelectedColumn(); int selectedRow = jTable1.getSelectedRow(); Object newColumnObj = jTable1.getValueAt(selectedRow, selectedColumn); String sql = ""; if (newColumnObj instanceof String && !newColumnObj.toString().trim().equals("")) { sql = "(dzyhp_name like \"%" + newColumnObj.toString() + "%\"" + " or zujima like \"%" + newColumnObj.toString().toLowerCase() + "%\")"; } return sql; } @Override public String[][] displayColumns() { return new String[][] { { "dzyhpId", "?ID" }, { "dzyhpName", "???" }, { "lylb.pihao", "??" } }; } @Override public void setBindedMap(HashMap bindedMap) { if (bindedMap != null) { Object dzyhpId = bindedMap.get("dzyhpId"); Object dzyhpName = bindedMap.get("dzyhpName"); Object dzyhpType = bindedMap.get("dzyhpType"); Object dzyhpPinpai = bindedMap.get("dzyhpPinpai"); Object gdzcXinghao = bindedMap.get("dzyhpXinghao"); // Object dzyhpValue = bindedMap.get("dzyhpValue"); Object gdzcDanwei = bindedMap.get("unitId"); editTable.insertValue(0, dzyhpId); editTable.insertValue(1, dzyhpName); editTable.insertValue(2, dzyhpType); editTable.insertValue(3, dzyhpPinpai); editTable.insertValue(4, gdzcXinghao); editTable.insertValue(5, gdzcDanwei); HashMap map = (HashMap) bindedMap.get("lylb"); pihao = (String) map.get("pihao"); saleprice = Float.parseFloat(map.get("price").toString()); editTable.insertValue(7, saleprice); editTable.insertValue(9, pihao); Object lycount = bindedMap.get("count"); // ZiChanLieBiaotb zclb = new ZiChanLieBiaotb(); // zclb.setCgsqId(jTextField1.getText()); // zclb.setCgzcId((Integer)dzyhpId); // zclb.setQuantity(0); // zc.add(zclb); //??? kucunmap.put(dzyhpId + pihao, lycount); } } }); jTable1.getModel().addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { int col = e.getColumn(); int row = e.getFirstRow(); if (col == 6 || col == 7) { if ((!(("" + jTable1.getValueAt(row, 6)).equals(""))) && (!(("" + jTable1.getValueAt(row, 7)).equals("")))) { int count = Integer.parseInt("" + jTable1.getValueAt(row, 6)); float price = Float.parseFloat("" + jTable1.getValueAt(row, 7)); jTable1.setValueAt(price * count, row, 8); } int rows = jTable1.getRowCount(); total = 0; for (int i = 0; i < rows; i++) { if (!(("" + jTable1.getValueAt(i, 8)).equals(""))) { total += Float.parseFloat("" + jTable1.getValueAt(i, 8)); } } totalprice.setText(total + ""); } } }); }
From source file:com.diversityarrays.kdxplore.curate.SampleEntryPanel.java
SampleEntryPanel(CurationData cd, IntFunction<Trait> traitProvider, TypedSampleMeasurementTableModel tsm, JTable table, TsmCellRenderer tsmCellRenderer, JToggleButton showPpiOption, Closure<Void> refreshFieldLayoutView, BiConsumer<Comparable<?>, List<CurationCellValue>> showChangedValue, SampleType[] sampleTypes) { this.curationData = cd; this.traitProvider = traitProvider; this.typedSampleTableModel = tsm; this.typedSampleTable = table; this.showPpiOption = showPpiOption; this.initialTableRowHeight = typedSampleTable.getRowHeight(); this.tsmCellRenderer = tsmCellRenderer; this.refreshFieldLayoutView = refreshFieldLayoutView; this.showChangedValue = showChangedValue; List<SampleType> list = new ArrayList<>(); list.add(NO_SAMPLE_TYPE);/*from w w w . j ava 2 s .c o m*/ for (SampleType st : sampleTypes) { list.add(st); sampleTypeById.put(st.getTypeId(), st); } sampleTypeCombo = new JComboBox<SampleType>(list.toArray(new SampleType[list.size()])); typedSampleTableModel.addTableModelListener(new TableModelListener() { @Override public void tableChanged(TableModelEvent e) { if (TableModelEvent.HEADER_ROW == e.getFirstRow()) { typedSampleTable.setAutoCreateColumnsFromModel(true); everSetData = false; } } }); showStatsAction.putValue(Action.SHORT_DESCRIPTION, Vocab.TOOLTIP_STATS_FOR_KDSMART_SAMPLES()); showStatsOption.setFont(showStatsOption.getFont().deriveFont(Font.BOLD)); showStatsOption.setPreferredSize(new Dimension(30, 30)); JLabel helpPanel = new JLabel(); helpPanel.setHorizontalAlignment(JLabel.CENTER); String html = "<HTML>Either enter a value or select<br>a <i>Source</i> for <b>Value From:</b>"; if (shouldShowSampleType(sampleTypes)) { html += "<BR>You may also select a <i>Sample Type</i> if it is relevant."; } helpPanel.setText(html); singleOrMultiCardPanel.add(helpPanel, CARD_SINGLE); singleOrMultiCardPanel.add(applyToPanel, CARD_MULTI); // singleOrMultiCardPanel.add(multiCellControlsPanel, CARD_MULTI); validationMessage.setBorder(new LineBorder(Color.LIGHT_GRAY)); validationMessage.setForeground(Color.RED); validationMessage.setBackground(new JLabel().getBackground()); validationMessage.setHorizontalAlignment(SwingConstants.CENTER); // validationMessage.setEditable(false); Box setButtons = Box.createHorizontalBox(); setButtons.add(new JButton(deleteAction)); setButtons.add(new JButton(notApplicableAction)); setButtons.add(new JButton(missingAction)); setButtons.add(new JButton(setValueAction)); deleteAction.putValue(Action.SHORT_DESCRIPTION, Vocab.TOOLTIP_SET_UNSET()); notApplicableAction.putValue(Action.SHORT_DESCRIPTION, Vocab.TOOLTIP_SET_NA()); missingAction.putValue(Action.SHORT_DESCRIPTION, Vocab.TOOLTIP_SET_MISSING()); setValueAction.putValue(Action.SHORT_DESCRIPTION, Vocab.TOOLTIP_SET_VALUE()); Box sampleType = Box.createHorizontalBox(); sampleType.add(new JLabel(Vocab.LABEL_SAMPLE_TYPE())); sampleType.add(sampleTypeCombo); statisticsControls = generateStatControls(); setBorder(new TitledBorder(new LineBorder(Color.GREEN.darker().darker()), "Sample Entry Panel")); GBH gbh = new GBH(this); int y = 0; gbh.add(0, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, statisticsControls); ++y; if (shouldShowSampleType(sampleTypes)) { sampleType.setBorder(new LineBorder(Color.RED)); sampleType.setToolTipText("DEVELOPER MODE: sampleType is possible hack for accept/suppress"); gbh.add(0, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, sampleType); ++y; } sampleSourceControls = Box.createHorizontalBox(); sampleSourceControls.add(new JLabel(Vocab.PROMPT_VALUES_FROM())); // sampleSourceControls.add(new JSeparator(JSeparator.VERTICAL)); sampleSourceControls.add(sampleSourceComboBox); sampleSourceControls.add(Box.createHorizontalGlue()); sampleSourceComboBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { updateSetValueAction(); } }); gbh.add(0, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, sampleSourceControls); ++y; gbh.add(0, y, 2, 1, GBH.HORZ, 1, 1, GBH.CENTER, valueDescription); ++y; gbh.add(0, y, 1, 1, GBH.NONE, 1, 1, GBH.WEST, showStatsOption); gbh.add(1, y, 1, 1, GBH.HORZ, 2, 1, GBH.CENTER, sampleValueTextField); ++y; gbh.add(0, y, 2, 1, GBH.NONE, 1, 1, GBH.CENTER, setButtons); ++y; gbh.add(0, y, 2, 1, GBH.HORZ, 2, 1, GBH.CENTER, validationMessage); ++y; gbh.add(0, y, 2, 1, GBH.HORZ, 2, 0, GBH.CENTER, singleOrMultiCardPanel); ++y; deleteAction.setEnabled(false); sampleSourceControls.setVisible(false); sampleValueTextField.setGrayWhenDisabled(true); sampleValueTextField.addActionListener(enterKeyListener); sampleValueTextField.getDocument().addDocumentListener(new DocumentListener() { @Override public void removeUpdate(DocumentEvent e) { updateSetValueAction(); } @Override public void insertUpdate(DocumentEvent e) { updateSetValueAction(); } @Override public void changedUpdate(DocumentEvent e) { updateSetValueAction(); } }); setValueAction.setEnabled(false); }