defaulttablemodel

setValueAt(Object aValue, int row, int col)

£可爱£侵袭症+ 提交于 2019-12-25 16:10:03
问题 I am trying to change a value in the Object[][] data in a defaultTableModel but I am getting a nullpointerexception at if (data[i][j] == userFolderName) I have tried changing the variable to "Kathy" just in case it wasn't reading the userName correctly but it still throws the exception. Can you please have a look at my code and see where I'm going wrong? public class Statistics extends JPanel { public Object[][] data; public DefaultTableModel model; public Statistics() { super(new GridLayout

setValueAt(Object aValue, int row, int col)

半城伤御伤魂 提交于 2019-12-25 16:08:10
问题 I am trying to change a value in the Object[][] data in a defaultTableModel but I am getting a nullpointerexception at if (data[i][j] == userFolderName) I have tried changing the variable to "Kathy" just in case it wasn't reading the userName correctly but it still throws the exception. Can you please have a look at my code and see where I'm going wrong? public class Statistics extends JPanel { public Object[][] data; public DefaultTableModel model; public Statistics() { super(new GridLayout

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

Unreported exception SQLException; must be caught or declared to be thrown error

落爺英雄遲暮 提交于 2019-12-24 10:56:16
问题 This allows me to grab data from my database, store it as a DefaultTableModel and pass that model onto my GUI - populating my jTable with database data. This is the method within my Account class: public static DefaultTableModel buildTableModel() throws SQLException { Vector<Vector<Object>> data = new Vector<Vector<Object>>(); Vector columns = new Vector(); PreparedStatement ps = null; ResultSet rs = null; try { String stmt = "SELECT * FROM APP.DATAVAULT"; ps = Main.getPreparedStatement(stmt)

DefaultTableModel without column names

这一生的挚爱 提交于 2019-12-23 17:27:40
问题 This class communicates with my database retrieves data and project them to a JTable.I used the DefaultTableModel but the column names won't appear.I instantiate this class in another class where i retrieve the table with the data through getTable( ) . package jtable; import javax.swing.*; import javax.swing.table.*; import java.sql.*; public class ControlDatabase { private JTable table; private Statement stmt; private DefaultTableModel model; private String all = "SELECT * FROM Players ORDER

jTable row count VS model row count

限于喜欢 提交于 2019-12-20 07:21:56
问题 I have a jTable which loads data from a DB query This load produces 32 results, thus 32 rows in the TableModel With myTable.getRowCount() i correctly get 32 Then i create a new empty model and load it into the table After that, if i call myTable.getRowCount() i still get 32 But if i call myModel.getRowCount() i correctly get 0! Why there should be difference between table.getRowCount() and model.getRowCount() if my table is using the model? ... System.out.println(myTable.getRowCount()); // 32

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

show an image when hover over a jtable cell

♀尐吖头ヾ 提交于 2019-12-19 10:28:01
问题 I have a JTable created with a DefaultTableModel, and I want to show an image when the mouse hovers over a particular cell of that JTable, and I need the image to be different for each cell. Thanks in advance 回答1: You can override prepareRenderer of the JTable and setToolTip for the cell/column/row component, and use some HTML for the tooltop, as see here and here For each different image you will need to get a different URL as the src of the img tag. You'll need to know some basic HTML for

JTable Row selection background problem.

你说的曾经没有我的故事 提交于 2019-12-18 05:25:36
问题 I have a JTable and to set a picture as background in JTable and other properties i used this code. tblMainView= new JTable(dtModel){ public Component prepareRenderer(TableCellRenderer renderer, int row, int column) { Component c = super.prepareRenderer( renderer, row, column); // We want renderer component to be transparent so background image // is visible if( c instanceof JComponent ) ((JComponent)c).setOpaque(false); return c; } ImageIcon image = new ImageIcon( "images/watermark.png" );

JTable: sorting by Integer

末鹿安然 提交于 2019-12-17 17:05:00
问题 I have a JTable, and i want to sort rows sometimes by integer (size column), sometimes by String (file path). So i searched it on google and i've arrived here. i've known that i've to override a method of DefaultTableModel , called getColumnClass . So i link here my code. class Personal_model extends DefaultTableModel{ Personal_model(String[][] s,String[] i){ super(s,i); } @Override public Class<?> getColumnClass(int columnIndex){ if (columnIndex!=2) return String.class; else return Integer