tablecelleditor

JTable stop cell editing without user click

北慕城南 提交于 2019-11-28 06:37:12
问题 I'm trying to solve a strange problem with my program. This program creates a series of GUI's and JTables that give a user the ability to generate an XML file. One of these tables is for creating the "statements". I won't get into detail as far as that except to say that the data is stored in multiple 2D arrays which are in turn stored in a hash map. Here is what happens. When a user enters the Statement screen a JTable is generated using the contents from the 2D array. This data populates

validate a table's cell using editors

最后都变了- 提交于 2019-11-28 00:25:10
I have a Password field editor for my JTable. I want to display an error message if the text length is less than 8 bit when the user clicks to edit another field. I have tried focus listeners. But its not working. Please help me because i have just started workin with java swing. class PasswordEditor extends DefaultCellEditor { TextBox m_passWord = new TextBox(); public PasswordEditor() { super(new TextBox()); } @Override public Object getCellEditorValue() { return this.m_passWord.getText(); } @Override public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected

JTable cell editor number format

喜夏-厌秋 提交于 2019-11-27 23:12:06
I need to show numbers in jTable with exact 2 decimal places. To accomplish this I have created a custom cell editor as: public class NumberCellEditor extends DefaultCellEditor { public NumberCellEditor(){ super(new JFormattedTextField()); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JFormattedTextField editor = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value!=null){ DecimalFormat numberFormat = new DecimalFormat("#,##0.00;(#,##0.00)"); editor.setFormatterFactory

Celleditor (JComboBox) in a specific row of a JTable

大憨熊 提交于 2019-11-27 22:53:07
问题 I don't know how to do to set a jcombobox in a specific row...for now I've this jcombobox for all rows but I want it in only one row: JComboBox cc = new JComboBox(); cc.addItem(jComboBox5.getSelectedItem()+"/"+jComboBox6.getSelectedItem()+"/"+jComboBox7.getSelectedItem()+" "+jComboBox1.getSelectedItem()+"."+jComboBox2.getSelectedItem()); jTable1.getColumnModel().getColumn(3).setCellEditor(new DefaultCellEditor(cc)); DefaultTableCellRenderer renderer = new DefaultTableCellRenderer(); renderer

How to delete a row from jtable

余生长醉 提交于 2019-11-27 15:54:09
I want to change the action of the button to delete. I have this code: package buttonexample; import java.awt.BorderLayout; import java.awt.Component; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.*; import javax.swing.table.AbstractTableModel; import javax.swing.table.DefaultTableModel; import javax.swing.table.TableCellRenderer; import javax.swing.table.TableModel; public class ButtonExample { public JTable table; public static void main(String[] args

easy and fast JTree Cell Editor

那年仲夏 提交于 2019-11-27 15:41:31
I have a JTree with a custom TreeModel and a custom TreeRenderer. The Tree Model contains a bunch of objects of different types. One of these types is displayed differently than the others: The displayed text is a concatenation of two fields of the object. When i edit the cell, I want to update one of these fields with the edited text. So far i got it working pretty well. My Problem: It is confusing when the text, which is displayed while editing, is the complete concatenated value of 2 fields, even though you're in fact just editing one of the fields. So i want to display only the content of

How to use custom JTable cell editor and cell renderer

孤人 提交于 2019-11-27 09:06:25
I have created a JTable with a custom table render and custom cell editor which gives the result in the image I created the panel shown in the first table cells using a separate class which extended JPanel. and add table values as, tbl.setCellEditor(new customCell()); tbl.getColumnModel().getColumn(0).setCellRenderer(new customCell()); DefaultTableModel dtm = (DefaultTableModel) tbl.getModel(); Vector v = new Vector(); v.add(new Panel()); v.add("Test"); dtm.addRow(v); v.clear(); v.add(new Panel()); v.add("Test 2"); dtm.addRow(v); And this is my table custom class to create this table, class

Adding JComboBox to a JTable cell [duplicate]

点点圈 提交于 2019-11-27 05:55:11
问题 Possible Duplicate: How to add a JComboBox to a JTable cell? I'm finding it difficult to add JComboBox to one of the cells of a JTable , I tried the code below but it's not working.. How can I add jcombobox to a particular cell? On pressing enter a new jcombobox should be added automatically to the desired column. jTable1 = new javax.swing.JTable(); mod=new DefaultTableModel(); mod.addColumn("No"); mod.addColumn("Item ID"); mod.addColumn("Units"); mod.addColumn("Amount"); mod.addColumn("UOM")

JTable cell editor number format

☆樱花仙子☆ 提交于 2019-11-26 23:16:23
问题 I need to show numbers in jTable with exact 2 decimal places. To accomplish this I have created a custom cell editor as: public class NumberCellEditor extends DefaultCellEditor { public NumberCellEditor(){ super(new JFormattedTextField()); } public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) { JFormattedTextField editor = (JFormattedTextField) super.getTableCellEditorComponent(table, value, isSelected, row, column); if (value!

validate a table's cell using editors

别来无恙 提交于 2019-11-26 21:42:22
问题 I have a Password field editor for my JTable. I want to display an error message if the text length is less than 8 bit when the user clicks to edit another field. I have tried focus listeners. But its not working. Please help me because i have just started workin with java swing. class PasswordEditor extends DefaultCellEditor { TextBox m_passWord = new TextBox(); public PasswordEditor() { super(new TextBox()); } @Override public Object getCellEditorValue() { return this.m_passWord.getText();