Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Sync changing column widths across multiple JTables

  1. #1
    Junior Member
    Join Date
    Jan 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question Sync changing column widths across multiple JTables

    I have an interesting case where there are three JTables that must be synced together in a rather peculiar fashion.

    The first column of all tables must resize together (have this working), and all other columns must resize together.

    Here is an image of the tables:
    table_sample.jpg

    I would like to resize all of the "Date" columns together so that the width of these are always consistent. Looking for suggestions.

    Here's pseudo code for what I want to happen:

    if (user resizes first column)
    resize first column of other two tables
    else if (user resizes another column)
    perform for each table 1, 2, and 3
    loop through all columns 2 through <MAX NUMBER COLUMNS>
    if (column != column being resized by user)
    resize column width to match user's resized column
    Here's what I've tried:

    Extended the TableColumnModelListener and implemented above in columnMarginChanged().
    Problem: Resizing of columns in code triggers events all tables, which in turn triggers events in all tables, etc, etc...
    Attempted Fix: Remove listeners for tables while columnMarginChanged()'s
    code is being executed, put listeners back afterwards.
    *** This does NOT seem to solve the problem. The other events are still being triggered.
    Attempted Fix: Implement custom TableColumnMode by extending DefaultTableColumnModel
    and overriding fireColumnMarginChanged() to add disabling logic.
    *** Did not work. Broke default functionality of the DefaultTableColumnModel.
    Tables would not automatically repaint when structure changed or data was updated.

    If someone could give me a simple working example, OR just tell me an alternative approach to try, I'd be very grateful.

    Regards,
    -Will


  2. #2
    Junior Member
    Join Date
    Jan 2012
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Sync changing column widths across multiple JTables

    Hmm, no ideas?

Similar Threads

  1. jTables and models
    By luisp88 in forum AWT / Java Swing
    Replies: 1
    Last Post: October 25th, 2011, 12:27 PM
  2. Sync movement with sound?
    By cl2606 in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 2nd, 2011, 05:12 PM
  3. Force Sync on Graphics2D?
    By Gerp in forum Java Theory & Questions
    Replies: 2
    Last Post: April 13th, 2011, 09:13 PM
  4. JTables with JButtons, I'm overlooking something
    By aussiemcgr in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 8th, 2010, 11:30 AM
  5. sync two diffrent kind of threads?
    By adamruss in forum Threads
    Replies: 1
    Last Post: January 10th, 2010, 08:59 PM

Tags for this Thread