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 3 of 3

Thread: JTable visual glitch with more than 25-100 rows

  1. #1
    Junior Member
    Join Date
    Nov 2022
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default JTable visual glitch with more than 25-100 rows

    Dear community, I have rather an unusual request. The product I'm working with has a visual glitch: if I add many (20-100, depends of the row's complexity) rows to the table, the table got broken, the rows get messed up, two rows get overlapped etc.. The vendor refuses consider it as a bug and answer me "[it] might be intrinsic to how java processes to render these strings". Sadly I don't have access to the source code, but quick google search provides some clues, it can be a fixed size of the JTable, that was indended to include a limited number of rows.

    Please share you opinion - is that a bug that impossible to fix?

    Low number of rows: all rows shown correctly:


    More rows, the first and last rows are shown incorrectly, some internal undelying xml code is shown, rows shown overlapped:


    More rows, some rows shown overlapped:
    Last edited by ITjazz; November 17th, 2022 at 06:21 PM.

  2. #2
    Junior Member jlbana's Avatar
    Join Date
    Dec 2022
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: JTable visual glitch with more than 25-100 rows

    You'd must set the row height manually, or embed a TableModelListener to re-calculate it upon modification.
    public class RowResizer implements TableModelListener
    {
    	private JTable table;
    	private int height;
     
    	public RowResizer(JTable table) {
    		this.table  = table;
    		this.height = table.getRowHeight();
    	}
     
    	@Override
    	public void tableChanged(TableModelEvent e) {
    		int i;
    		for (i = 0; i < table.getRowCount(); ++i) {
    			TableCellRenderer renderer = table.getCellRenderer(0, 0);
    			Component component = table.prepareRenderer(renderer, 0, 0);
    			height = Math.max(height, (component.getPreferredSize()).height);
    		}
    		table.setRowHeight(height);
    	}
    }
    table = new JTable();
    model = (DefaultTableModel) table.getModel();
    model.addTableModelListener(new RowResizer(table));
    https://web.archive.org/web/20121022...RowHeight.html

  3. #3
    Member Helium c2's Avatar
    Join Date
    Nov 2023
    Location
    Kekaha, Kaua'i
    Posts
    102
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: JTable visual glitch with more than 25-100 rows

     
    @Override
    	public void tableChanged(TableModelEvent e) {
    		int i;
    		for (i = 0; i < table.getRowCount(); ++i) {
    			TableCellRenderer renderer = table.getCellRenderer(0, 0);
    			Component component = table.prepareRenderer(renderer, 0, 0);
    			height = Math.max(height, (component.getPreferredSize()).height);
    		}
    		table.setRowHeight(height);
    	}

    Where'd you find all the related class files and methods? I want to know where on the internet you can find this things.

    --- Update ---

    Does the above method need a mouseListener too? Such ass addMouseListener. In the methods that are used for this one specific file. Making a table in a Java Container.

Similar Threads

  1. How to stop adding duplicate rows in java JTable?
    By Reznik in forum Computer Support
    Replies: 1
    Last Post: July 15th, 2022, 06:06 AM
  2. Title screen Glitch (Cant Bust ERROR)
    By ErrorBuster in forum What's Wrong With My Code?
    Replies: 4
    Last Post: May 3rd, 2012, 02:45 PM
  3. Netbeams having a mysterious glitch about a work directory not existing.
    By javapenguin in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 14th, 2012, 02:59 PM
  4. IDE (Visual Editor)
    By bbr201 in forum Java Theory & Questions
    Replies: 5
    Last Post: August 7th, 2010, 12:33 PM
  5. Visual Swing 4 Eclipse
    By helloworld922 in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: January 28th, 2010, 04:34 AM