tablemodel

JTable will set to editable after converting ResultSet to TableModel with DbUtils. How to make it non-editable again?

て烟熏妆下的殇ゞ 提交于 2019-11-27 07:30:39
问题 Here is My Code for doing this` public static void addSong(String[] fileDetail, JTable SongData_Table) { try { con = DBConnection.getCon(); stmt = con.createStatement(); stmt.executeUpdate("insert into songs values (null,'" + fileDetail[0] + "', '" + fileDetail[1] + "',null,null)"); ResultSet rs = stmt.executeQuery("select * from songs"); TableModel model = DbUtils.resultSetToTableModel(rs); SongData_Table.setModel(model); if (con != null) { stmt.close(); con.close(); } } catch (SQLException

Cell validation in JTable

纵然是瞬间 提交于 2019-11-27 07:04:00
问题 I have a JTable that needs cell validation for the cells where the user can input text. When a user enters invalid text the border of the cell turns red. I've managed to get this working associating a two dimension array to flag if each cell has errors or not. The problem is that the user must be able to reorder the table (by column). I have to store the error flag in the table model, not separatly. Anyone has ideas how to do this? 回答1: Also consider a custom TableCellEditor , seen here and

Working with several custom table models avoiding repetitive code

倾然丶 夕夏残阳落幕 提交于 2019-11-27 05:37:28
I'm working in a project in which we have several domain classes to model business data. Those classes are simple POJO's and I have to display several tables using them. For example, consider this class: public class Customer { private Long id; private Date entryDate; private String name; private String address; private String phoneNumber; public Customer(Long id, Date entryDate, String name, String address, String phoneNumber) { this.id = id; this.entryDate = entryDate; this.nombre = name; this.domicilio = address; this.telefono = phoneNumber; } // Getters and setters here } I have created

How to refresh data in JTable I am using TableModel

ぐ巨炮叔叔 提交于 2019-11-27 05:12:44
Hi, I have created my TableModel and want to refresh JTable once I added a new row. What should be added to the listener to "refresh" JTable? public class MyTableModel implements TableModel { private Set<TableModelListener> listeners = new HashSet<TableModelListener>(); //List<Staff> staffs = Factory.getInstance().getStaffDAO().getAllStaff(); private List<Staff> staffs; public MyTableModel(List<Staff> staffs){ this.staffs = staffs; } @Override public int getRowCount() { return staffs.size(); } @Override public int getColumnCount() { return 5; } @Override public String getColumnName(int

How to set icon in a column of JTable?

二次信任 提交于 2019-11-27 02:02:25
I am able to set the column's header but not able to set icon in all the rows of first column of JTable. public class iconRenderer extends DefaultTableCellRenderer{ public Component getTableCellRendererComponent(JTable table,Object obj,boolean isSelected,boolean hasFocus,int row,int column){ imageicon i=(imageicon)obj; if(obj==i) setIcon(i.imageIcon); setBorder(UIManager.getBorder("TableHeader.cellBorder")); setHorizontalAlignment(JLabel.CENTER); return this; } } public class imageicon{ ImageIcon imageIcon; imageicon(ImageIcon icon){ imageIcon=icon; } } and below lines in my BuildTable()

Mass produce JTables

≯℡__Kan透↙ 提交于 2019-11-26 23:41:30
问题 I want to make 25 JTables. I generate the table names by doing: for(int i=0; i < 26; i++) { TableNames[i] = "Table" + i + ""; ... How can I go about using these String names in the array as the new JTable names? i.e. TableNames[i] = new JTable(model){ ... 回答1: Instead of an array, consider using a List<JTable> or List<TableModel> . Pass the name to the table's constructor or factory method. The example below uses the Component 's name, but a JComponent 's client property may be more versatile

Java, change a cell content as a function of another cell in the same row

我与影子孤独终老i 提交于 2019-11-26 20:57:13
I need some help for my problem. I have a table with e.g. a double column and a string column. If the value in the double column is negativ, the string should be "negativ". And the other way if the value is positiv, the string should be "positiv". The problem is now if I edit the double value in the jTable, the string should also be updated. Update to my question, the actual code look like this: But it doesn't work, because the string in the second column wont be updated after I edit the first column value. It only works when I start the program the first time. import java.util.Vector; import

Change Column Type of jtable when table populate from resultset

只谈情不闲聊 提交于 2019-11-26 18:38:40
问题 I have worker for fill the jtable from resultset like below; public class WorkerFillTable extends SwingWorker<DefaultTableModel, DefaultTableModel> { private DefaultTableModel modeltable; public WorkerFillTable(DefaultTableModel modeltable) { this.modeltable = modeltable; } @Override protected DefaultTableModel doInBackground() throws Exception { ResultSet rs; Statement stmt; String query = "select Name,ID,Status,IsActive from current_conf\n" + "order by Name,ID"; Class.forName("com.microsoft

Working with several custom table models avoiding repetitive code

本秂侑毒 提交于 2019-11-26 12:49:28
问题 I\'m working in a project in which we have several domain classes to model business data. Those classes are simple POJO\'s and I have to display several tables using them. For example, consider this class: public class Customer { private Long id; private Date entryDate; private String name; private String address; private String phoneNumber; public Customer(Long id, Date entryDate, String name, String address, String phoneNumber) { this.id = id; this.entryDate = entryDate; this.nombre = name;

How to implement dynamic GUI in swing

两盒软妹~` 提交于 2019-11-26 11:52:26
First of all, apologies for posting something perhaps a bit excessively specific, but I'm not very experienced with Swing, and can't seem to find good examples that fit my needs. So I'm trying to figure out the best way to implement the a dynamic GUI for choosing filtering criteria in Swing: The underlying model is a class containing a list of criteria that can be negated (i.e. applied with a NOT-prefix), and a property indicating whether these should be combined with AND or OR. The GUI would allow the user to add, change or remove criteria, and select the combination operator (and/or). The