jtable

How to make one mySQL's table column invisible

僤鯓⒐⒋嵵緔 提交于 2019-12-20 03:05:01
问题 I am running a query on ID column but I don't want it to be visible in my frame/pane. How can I achieve this? Shall I make another table, is there a function in sql/mysql which allows to hide columns? I tried to google it but havent found anything yet. Here is the code: public void tableChanged(TableModelEvent e) { int row = e.getFirstRow(); int col = e.getColumn(); model = (MyTableModel) e.getSource(); String stulpPav = model.getColumnName(col); Object data = model.getValueAt(row, col);

Adding button to jtable

拥有回忆 提交于 2019-12-20 02:34:28
问题 I searched for tutorials for adding button in jtable and found a class file from, http://tips4java.wordpress.com/2009/07/12/table-button-column/ Where to set label for the button? [code] private void createTable(){ model = new DefaultTableModel(); editorTable.setModel(model); model.addColumn("COL1"); model.addColumn("COL2"); model.addColumn("ADD"); model.addColumn("DELETE"); model.addRow(new Object[]{"DATA1", "DATA2"}); Action delete = new AbstractAction() { @Override public void

JTable refresh are not displayed

岁酱吖の 提交于 2019-12-20 02:27:19
问题 I'm desperately trying to convince my JTable to refresh when I change its data. The data are stored in a global singleton, TreeSet , that I'm working with. Whenever the TreeSet s data is altered, an event is fired to refresh the TableModel . For test purposes, I replaced this by a simple Timer firing events. Each time an event is fired, an element from the TreeSet is removed to simulate changes in the data. The event fires and the TableClass receives it and processes it as expected, but when

How to select the last inserted row in a JTable?

一世执手 提交于 2019-12-20 02:13:57
问题 I have a JTable with two columns and a table model that uses a class which works with a hash map. The elements of this map are the table rows. Every time I add a new element I need the element to be selected, regardless of any sorting. Now, I've tried using the following method: int lastRow = table.convertRowIndexToView(tableModel.getRowCount() - 1); table.setRowSelectionInterval(lastRow, lastRow); The problem is, this works only when I'm adding data in a sorted fashion (e.g. "A", "B", "C"

How to select the last inserted row in a JTable?

寵の児 提交于 2019-12-20 02:13:50
问题 I have a JTable with two columns and a table model that uses a class which works with a hash map. The elements of this map are the table rows. Every time I add a new element I need the element to be selected, regardless of any sorting. Now, I've tried using the following method: int lastRow = table.convertRowIndexToView(tableModel.getRowCount() - 1); table.setRowSelectionInterval(lastRow, lastRow); The problem is, this works only when I'm adding data in a sorted fashion (e.g. "A", "B", "C"

JTable rendering JPanel

痴心易碎 提交于 2019-12-20 01:46:17
问题 I have a one column JTable to which I set a custom TableCellRenderer that return a custom JPanel in its getTableCellRendererComponent method. The custom JPanel contains several JTextField and JButton and only one instance of the custom JPanel is created and in the getTableCellRendererComponent method I just set its JTextField values from data model object. In order to make the JTextFiel editable and JButton clickable I had to set the isCellEditable method from JTable model to true as well as

apache poi: saving jtable to a file

落花浮王杯 提交于 2019-12-19 18:55:46
问题 I've recently started working with java and I'm facing some issues with the apache poi library when I need to create an excel file starting from a jTable. I've read many threads and come up with some code which just won't work (even if this is pretty easy stuff and there were many examples, which makes me look even more dumb) and I was hoping someone could help me out. So here are the questions: a) why does the for loop, which is supposed to write the excel file, not fill every cell? (the

Dynamic jcombobox items inside jtable

坚强是说给别人听的谎言 提交于 2019-12-19 11:55:53
问题 I am trying to create a Jtable with two combobox in each row. I have checked for tutorials on that and found that I can add static data inside combobox. But how come I can have dynamic data loaded into a combobox. Even, whenever the user selects the combobox 1 from the row, then based on that, the combobox 2 will be updated. Can anybody help me on this? If I do removeAllItems() from the combobox, then the combobox 2 will updated, but I am unable to add new entries. Thanks in advance. 回答1:

Programmatically enable editing a JTable cell on keystroke

十年热恋 提交于 2019-12-19 11:51:24
问题 I would like to enable editing a JTable cell on a key, say F2. I know that by default double clicking will enable editing, but is there a way to bind that event to a key? I tried this link JTable edit on keypress but it doesn't work for me. Here is my code: public class DatabaseJTable extends JTable implements MouseListener { public DatabaseJTable(Object [][] data, Object [] columnNames) { super(data, columnNames); InputMap inputMap = this.getInputMap(JComponent.WHEN_FOCUSED); ActionMap

Jtable Look and feel of editing cell

一曲冷凌霜 提交于 2019-12-19 11:47:14
问题 There is a JTable with DefaultTableModel . There is table's setforeground , setbackground and setselectioncolor methods. Also when you are editing the cell you have table.setDefaultEditor(Object.class, new DefaultCellEditor(field)) method to change the editing cell's font color. Now how to change the border color of the editing cell. Thankyou.` 回答1: You can use any of the following keys in UIManager.put() to affect the corresponding Border : Table.focusCellHighlightBorder Table