Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8466383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:19:32+00:00 2026-06-10T15:19:32+00:00

To hide a column from only the view of JTable, i am using the

  • 0

To hide a column from only the view of JTable, i am using the removeColumn() method. But it throws the exception

Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
at java.util.Vector.elementAt(Vector.java:470)
at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)
at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:648)

i think, after removing column from the view, if i modified the model, then this exception pops out. is it because of there is no column in view, while the model is updating the table ?

What is the best way to hide the column in view in JTable ? insteading of setting the sizes to 0

EDIT:
The exception is not occuring regularly. it is a random exception. Anyway here is the code:

    @Override
        protected Object doInBackground() throws Exception {
        ........
        resultDTO=//get data from database
        tableModel.setDataVector(resultDTO.getAllRows(), tableModel.getColumnNames());    
        // hide column
        table.removeColumn(table.getColumnModel().getColumn(7));
            System.out.println("table column count : " + table.getColumnCount());
            System.out.println("model column count : " + tableModel.getColumnCount());
        ........
        .........       
        }



initial result (with out any data in table, at application startup): 
table column count : 7
model column count : 8

after populating data (first running of above method):
table column count : 7
model column count : 8

after few times executing : 
table column count : 7
model column count : 8
Exception in thread "AWT-EventQueue-0" java.lang.ArrayIndexOutOfBoundsException: 7 >= 7
    at java.util.Vector.elementAt(Vector.java:470)
    at javax.swing.table.DefaultTableColumnModel.getColumn(DefaultTableColumnModel.java:294)
    at javax.swing.plaf.basic.BasicTableHeaderUI.paint(BasicTableHeaderUI.java:648)
    at javax.swing.plaf.synth.SynthTableHeaderUI.paint(SynthTableHeaderUI.java:173)

Some times the above exception occures when i first load the data, and sometimes its not.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:19:33+00:00Added an answer on June 10, 2026 at 3:19 pm

    You’re trying to update UI components out side of the Event Dispatching Thread, this is NEVER a good idea

    protected Object doInBackground() throws Exception {
        ........
        resultDTO=//get data from database
        // This shouldn't be done here
        tableModel.setDataVector(resultDTO.getAllRows(), tableModel.getColumnNames());  
        // and neither should this
        // hide column
        table.removeColumn(table.getColumnModel().getColumn(7));
    

    Thumbs up for using a SwingWorker though. The problem is, Swing components are not thread safe and you should never try to update them outside of he EDT, because they cause unexpected results (like you’ve just encounted).

    Rather then setting the row data directly, I’d suggest using the publish/process methods. If you can’t decide when to remove the column, I’d remove it either before the worker executes or in the workers done method

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

How do you hide the column names and row count in the output from
How can we hide the column of the table by using jquery < table
I would like to hide the ID column of a Kendo grid but still
I'm using the column chooser feature of jQgrid. Is there a way to hide
How to show and hide one particular column in Mouse Over and Mouse out
I have a table column I’m trying to expand and hide. jQuery seems to
I know of several approaches using a macro (VBA) to show/hide columns and rows
I can't hide my div using some i.e. explode effect in jquery ui, It
I am using jQuery to load the search results from a php class when
I have a view-based NSTableView that usually has one column in it. However, at

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.