defaulttablemodel

JTable Row selection background problem.

梦想的初衷 提交于 2019-11-29 08:52:33
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" ); public void paint( Graphics g ) { // First draw the background image - tiled Dimension d = getSize();

How to make only one checkbox selectable in JTable Column

末鹿安然 提交于 2019-11-28 14:28:20
I am using DefaultTableModel as follows: DefaultTableModel model = new DefaultTableModel (COLUMNS, 0 ) { @Override public boolean isCellEditable(int row, int column) { return (getColumnName(column).equals("Selected")); } public Class getColumnClass(int columnIndex) { if(getColumnName(columnIndex).equals("Selected")) return Boolean.class; return super.getColumnClass(columnIndex); } }; Now I want to make only one checkbox selectable in the column "Selected". How can this be done. I have tried following method also but its not working. public void fireTableCellUpdated(int row,int column) { if

calculating in jtable with %, total

匆匆过客 提交于 2019-11-28 12:56:17
问题 I am almost at the end of my project and have some problems solving it. I m a chef who wants his own application what is relevant for his own bussines My form is called Recipes and have Qty unitprice, % used. So lets say, you have 1kg apples for 5 euro. At the end of cleaning you just have 800 grams of apples. So i have paid 20 percent more. example Item is always 100%, Qty 5, Unitprice 5, Used% 100% total = 25 Qty 5, Unitprice 5, Used% 70%, Total= 32.5 ( must increase with 30 percent) At the

re-size JTable when useing Default table model

半腔热情 提交于 2019-11-28 09:56:06
问题 I have a JTable built using DefaultModel which is displayed in JPane but I would like to re-size the table to make it bigger. Could any one please explain how I could do that? I have tried the following code: TableColumnModel colsize = t1.getColumnModel(); for(int i=0; i<cols; i++){ colsize.getColumn(i).setPreferredWidth(200); } but it did not work. 回答1: To size up the table#setPreferredSize(). table.setPreferredSize(new Dimension(500, 500)); To size up the columns table#getColumn(). table

How to hide a particlar column in DefaultTableModel from displaying it in table?

╄→尐↘猪︶ㄣ 提交于 2019-11-28 09:39:19
问题 I am using Java Swingx framework. I have 4 columns in my DefaultTableModel object. I wish to display only 3 of the columns. But, I need all four for computing. Actual data model S.No. | ID | GDC ID | Decsription What I want to display in table S.No.| GDC ID | Decsription Is it possible to hide or omit only one column from rendering? Please guide me. 回答1: by default minimum size is 10 pixels widht, you can to remove / add column from JTable view, column presents in the XxxTableModel, you can

Jtable doesn't refresh/update data

巧了我就是萌 提交于 2019-11-28 05:38:54
问题 I have a problem with JTable / JScrollPane . My data table is not refreshing/updating. I am using DefultTableModel and according to the code everything is fine and I don't have any errors. Also I have a table with paging and that's why I am using action listeners and buttons "prev" and "next". I am passing from other function to function that is coded in class where is JTable . Problem is that I fill arrays which contains data for table but table won't update/refresh it. Here is my code.

Add column to exiting TableModel

梦想与她 提交于 2019-11-27 14:52:33
I have a class; public class A extends AbstractTableModel { ... } Using ResultSetMetaData I build the TableModel to match my result set from the database. public class B extends JPanel { ... } In class B where I extends JPanel and added class A to show my table. I want to be able to add new columns base on a condition to the table model. I have tried googling around but most example shown are based on the DefaultTableModel not AbstractTableModel . Do anyone know how to achieve this? Just extend DefaultTableModel and then you have access to all of its methods. DefaultTableModel also extends

How to make only one checkbox selectable in JTable Column

浪子不回头ぞ 提交于 2019-11-27 08:47:02
问题 I am using DefaultTableModel as follows: DefaultTableModel model = new DefaultTableModel (COLUMNS, 0 ) { @Override public boolean isCellEditable(int row, int column) { return (getColumnName(column).equals("Selected")); } public Class getColumnClass(int columnIndex) { if(getColumnName(columnIndex).equals("Selected")) return Boolean.class; return super.getColumnClass(columnIndex); } }; Now I want to make only one checkbox selectable in the column "Selected". How can this be done. I have tried

How to make cells of JTable non-editable, but selectable [duplicate]

醉酒当歌 提交于 2019-11-27 08:03:22
问题 This question already has an answer here: How to make a JTable non-editable 7 answers I have overridden the isCellEditable() method of class JTable in my code to make the cells of my JTable non-editable but selectable, but the cells are still editable. How do I solve this problem? import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; import javax.swing.table.DefaultTableModel; public class A

Populating jTable using database data

风流意气都作罢 提交于 2019-11-27 02:17:01
I am trying to populate a Netbeans GUI-builder jTable using my Derby database data. I am using the following code, in my Account.java class: public DefaultTableModel getData() { try { String stmt = "SELECT * FROM APP.DATAVAULT"; PreparedStatement ps = Main.getPreparedStatement(stmt); ResultSet rs = ps.executeQuery(); ResultSetMetaData md = rs.getMetaData(); int columnCount = md.getColumnCount(); Vector columns = new Vector(columnCount); //store column names for (int i = 1; i <= columnCount; i++) { columns.add(md.getColumnName(i)); } Vector data = new Vector(); Vector row; while (rs.next()) {