473,469 Members | 1,513 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

JTable column model issues

5 New Member
Hi all. I've defined a custom TableModel so I can use custom types for my JTable. However, because of this, the table's TableColumnModel is totally out of sync with the model (ie. it isn't populated with any column data at all. No TableColumns or anything). This is annoying, since I need some reference to TableColumn objects (to do some column header rendering stuff).

Are there any good tutorials or examples that show how to ensure column models are in sync with custom table models, so that when you add data/columns to the model, they are also added to the column model?

I hope this post is clear.
Apr 20 '09 #1
3 3752
r035198x
13,262 MVP
Nah, the post is not clear to me. You extended DefaultTableModel and set an instance of that class to be the TableModel of a JTable, right? What is the problem now?
Apr 20 '09 #2
JHuman
5 New Member
Yes.

Basically, in the custom model, the columns are represented by a list of custom types. On overriden methods like getColumnName() and getColumnCount(), I simply interact with this list to return the appropriate value.

However, the column model of the JTable has no knowledge of this list of custom types. Because addColumn() is never called on it, it is not populated with any TableColumns. This poses a problem, since I want to set the renderers for column headers in the table, but the only way to do that is by calling setHeaderRenderer() on TableColumn types, but there aren't any actually being created (since I use a list of custom types).

How do I fix this? Or am I doing it wrong? Should custom column types be added to a custom column model rather than a custom table model?

EDIT: basically, I'm looking for a way to ensure that any data in the custom table model is reflected in the default column model.
Apr 20 '09 #3
r035198x
13,262 MVP
See if Sun's tutorial will help. I'm not sure that I fully graps what you are trying to do. Perhaps you just want to define a custom TableCellRenderer?
Apr 20 '09 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ben Munday | last post by:
Hi all, I have a problem with a Checkbox in a JTable. When i add the Checkbox into the JTable it displays the String representation of the Checkbox, which is not what i want. So, i created a...
5
by: Bernard Koninckx | last post by:
Hi everybody, The following code (putted in a inherited object from AbstractTableModel object) make some errors : public void deleteRow(int rowToDelete){ try{ Object dataObject =...
1
by: asd | last post by:
I need to make the cells in the 1st column look like the column header. I tried the following code but it didn't change anything: private void rendererTest() { TableColumn column =...
1
by: raysaun | last post by:
I am trying to set a TableCellEditor for a JTable, however, the editor never seems to get called. I can not even get a simplified version (below) to work. When I put a breakpoint on the return...
3
by: Derrick | last post by:
What is the C# equivalent of JTable? I need a UI that contains a table with variable rows, that I can add combo boxes and buttons to for columns. Thanks in advance! Derrick
0
by: nellu | last post by:
hi to all i have a JTable with n Rows and 5 Cols. i want to give search option in my program. program select a row dynamically. my code is like this ********************************* table =...
7
blazedaces
by: blazedaces | last post by:
Hi guys, what I'm I have is a jtable with boolean variables in the first column and text in the next two (checkboxes). I want my tableChanged method to make it so when I check one of the checkboxes...
1
by: emekadavid | last post by:
can anyone help me flesh out the problem? I wanted to insert a combo box into one of the columns of a JTable. although the combo box is drawn, the list of the data model fails to render. ...
6
by: raggwd | last post by:
Hi, I have a JTable and implemented a model. I implemented the setValueAt(...) method to reflect the user input in my model. However, the setValueAt(...) method is not reliable enough, because it...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.