473,420 Members | 1,552 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,420 software developers and data experts.

Problems with extending JTables

5
Hey guys, I'm having a few problems with a JTable subclass I'm making. The constructor:

Expand|Select|Wrap|Line Numbers
  1. public CustomTable()
  2.   {
  3.     super();
  4.     TableColumn col = new TableColumn();
  5.     col.setCellRenderer(new CustomCellRenderer());
  6.     col.setHeaderValue("Blah");
  7.     DefaultTableModel model = ((DefaultTableModel)getModel());
  8.     model.addColumn(col);
  9.     getColumnModel().addColumn(col); 
  10.   }
When I call addRow(), it gives me an array index out of bounds exception if I do not call the bolded line. However, when I do call that line, I get duplicate columns appearing (one in the table model, one in the column model). I tried not adding the column to the column model, and that works, but then when the column is displayed only via the table model, any custom cell renderers I use don't work, and the column doesn't display the header value I set it to either (just displays the toString() of the TableColumn object).

Any help? What is the proper way to add columns?
Apr 16 '09 #1
1 1501
JosAH
11,448 Expert 8TB
Only add your new column to your DefaultTableModel given its name. The column will be intially empty but you can fill it yourself later. See the API documentation for the DefaultTableModel class.

kind regards,

Jos
Apr 16 '09 #2

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

Similar topics

0
by: Andrew Yinger | last post by:
Hi. I have recently encountered a serious problem with mysql: the mysqld-nt service pegs the processor at 100% after I start it. I noticed this right after a crash of the service, and the size...
54
by: tshad | last post by:
I have a function: function SalaryDisplay(me) { var salaryMinLabel = document.getElementById("SalaryMin"); salaryMinLabel.value = 200; alert("after setting salaryMinLabel = " +...
3
by: Flip | last post by:
I'm looking at the O'Reilly Programming C# book and I have a question about extending and combining interfaces syntax. It just looks a bit odd to me, the two syntaxes look identical, but how does...
5
by: vbgunz | last post by:
Hello everyone. I own two books. Learning Python and Python in a nutshell. When cross referencing the two books to try and clarify the ideas behind extending methods and delegates, this is where...
0
by: deanfamily | last post by:
Regarding JTables, if you call one with data in and display it (like in a new window) and close it, does it become protected? Reason I am asking is that I am displaying a table with data in,...
3
by: katis | last post by:
Hi all :) Is it posible in xsd to change only minOccurs value of element in complex type by extending this type? The problem I'm trying to solve is this: I have two complex types -...
2
by: TheHobbit | last post by:
Hi there I am a real newbie to CSS so please excuse any daft questions! I am trying to create a page with a header that contains a small square logo in top left corner with 2 longer divs to the rigt...
14
by: julie.siebel | last post by:
I've been wrestling with a really complex page. All the data is drawn down via SQL, the page is built via VBScript, and then controlled through javascript. It's a page for a travel company that...
0
by: marcell71 | last post by:
I'm trying to get Boost.Python to working using the instructions here: http://www.boost.org/libs/python/doc/building.html. I am on step 3.1.4 and am getting a linking error that I can't figure out....
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
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,...
0
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...

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.