jtable

Update JTable after delete or insert

风格不统一 提交于 2019-12-24 18:25:15
问题 I have a JTable that is populated by an Access DB using a ResultSet & AbstractTableModel . I have a method that deletes the record from the DB correctly but am having trouble refreshing the current view of the table model. I've looked at similar posts and have tried using fireTableRowsDeleted and fireTableDataChanged but have had no luck. I also noticed that other posts mention the use of the DefaultTableModel as it has add/remove row methods but the code I have working is from my Java

Update JTable after delete or insert

随声附和 提交于 2019-12-24 18:24:01
问题 I have a JTable that is populated by an Access DB using a ResultSet & AbstractTableModel . I have a method that deletes the record from the DB correctly but am having trouble refreshing the current view of the table model. I've looked at similar posts and have tried using fireTableRowsDeleted and fireTableDataChanged but have had no luck. I also noticed that other posts mention the use of the DefaultTableModel as it has add/remove row methods but the code I have working is from my Java

Get row values of ticked checkbox in jtable

你离开我真会死。 提交于 2019-12-24 15:33:38
问题 class TableModel extends AbstractTableModel { Object rowData[][] = DataAccess.getSentences(); String columnNames[] = {"Category", "Sentences", "Boolean"}; public int getColumnCount() { return columnNames.length; } public String getColumnName(int column) { return columnNames[column]; } public int getRowCount() { return rowData.length; } public Object getValueAt(int row, int column) { return rowData[row][column]; } public Class getColumnClass(int column) { return (getValueAt(0, column).getClass

JTable which is scrollable horizontally AND grows to fill parent container

妖精的绣舞 提交于 2019-12-24 15:15:37
问题 I want to put a JTable in a JScrollPane and want it to: be scrollable horizontally and vertically (only if it has content that makes it larger than parent container) automatically grow to fill parent container if needed (in both directions) only have either/both scroll bar(s) when needed The JList behaves exactly like this, btw. But I have found no easy way to accomplish all goals simultaneously with a JTable . The easy way to accomplish the first is to disable auto-resizing, but that then

How to make a specific jTable boolean column editable

二次信任 提交于 2019-12-24 15:05:15
问题 I have a method that returns a DefaultTableModel populated by a database. What I wanted to do is add boolean check boxes to each records returned by adding a new boolean column to the returned DefaultTableModel instance. The user should be able to only click/unclick these checkboxes (Multiple selection should be allowed) to manipulate some map objects I have in the GUI. Other columns should be un-editable. Any ideas on how to achieve this? So far I have gone up to the following point, I have

TableColumnModelListener. JPanel revalidate() method ruins swing elements composition

喜欢而已 提交于 2019-12-24 14:53:10
问题 Problem description: originally there were two tables: At the top of the left table there are two elements: JTextField and JComboBox, which are put into one separate JPanel. These two elementes are needed for the table filtering purposes, that is, changing selected combo box element or typing something in the JTextField get table on the left filtered out. I tried to implement TableColumnModelListener interface in order to connect JTextField and JComboBox elements to the table. The result was

JTable height calculation

匆匆过客 提交于 2019-12-24 14:34:21
问题 Solution jtable.getHeight does not include header element jtable.getRowHeight include margin and the example has 15px actual height, not 14px More clear example RO 16 R1 16 R2 16 HEIGHT 48 INTERCELL java.awt.Dimension[width=1,height=1] MARGIN 1 I have JTable with 3 rows. Each row is 16px . And each row margin 1px. So I suspect that table height should be 16 + 1 + 16 + 1 + 16 = 50px BUT getHeight returns 48px Also I did streenshot. Each row has 14px height actually. How how is it possible????

JTable alway can not get correct rowIndex for inner ComboBox

删除回忆录丶 提交于 2019-12-24 14:17:01
问题 I have a JTable which its one column cell is JComboBox . But when try to get row count when click the table JComboBox cell, I found the row index always return error value (alway is the last click row index). public class TableComboBoxTest extends JFrame { private JTable table; private DefaultTableModel tableModel; private Object[][] tableCells; private final String[] TABLE_COLUMNS = {"No.1"}; private final String[] YES_NO_SELECTION = {"Yes", "No"}; public TableComboBoxTest() { Container pane

Adding icons to jTable in different rows

梦想的初衷 提交于 2019-12-24 12:47:24
问题 I have a jTable that I have created to display the names of countries and the flag icons in the cells next to the names. How can I display each icon in the same column but different rows using the ImageIcon class, without displaying just a string? The following is what I have written to display the France flag icon at a certain place in the jTable but it just displays the string ImageIcon icon = new ImageIcon("http://www.stoma.fr/assets/images/French_Flag_Small_Icon.jpg"); jTable.setValueAt

Format a Jtable Cell, if illegal format, then do nothing

人走茶凉 提交于 2019-12-24 11:19:29
问题 Say I have following columns in my Jtable: {"Item", "Price"} I want format the price column to "0.00" format. But if user enter an illegal string, then keep the original value of the cell. ex, when the price is "1.23", but when user want to enter "abc", then the cell should still be "1.23" How could I do this? Thanks 回答1: Let's split your big problemn into smaller ones. First, you want to have items of your Price column to be displayed according to a specified format, which you can achieve