• Simple fix for JTable view?

    From Eric Douglas@21:1/5 to All on Wed Jun 17 04:38:15 2020
    Here's a simple sample that reproduces what my app is doing.
    If it matters, I am running JRE 11.0.7_10 from AdoptOpenJDK
    If I scroll down and back up, the text on my table disappears. It reappears if I click on the table.


    public static void main(String[] args) {

    EventQueue.invokeLater(() -> {
    JFrame win1 = new JFrame();
    Container p1 = win1.getContentPane();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    JPanel p4 = new JPanel();
    JPanel p5 = new JPanel();
    JPanel p6 = new JPanel();
    JPanel p7 = new JPanel();
    p5.add(p4);
    p6.add(p5);
    p7.add(p6);
    JScrollPane sp1 = new JScrollPane(p7);
    p1.add(p2);
    p2.add(p3);
    p3.add(sp1);
    win1.setPreferredSize(new Dimension(640,480));
    Object[][] data = new String[][] {{"data1"},{"data2"},{"data3"}};
    String[] cols = new String[] {"col1"};
    DefaultTableModel model = new DefaultTableModel(data,cols);
    JTable t1 = new JTable(model);
    p4.setLayout(new BoxLayout(p4, BoxLayout.PAGE_AXIS));
    p4.add(t1);
    for (int i = 0; i < 10; i++) {
    p4.add(new JLabel("Label " + i));
    }
    sp1.setPreferredSize(new Dimension(150,150));

    win1.setSize(new Dimension(800,600));
    win1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    win1.setVisible(true);
    });

    }

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin Gregorie@21:1/5 to Eric Douglas on Wed Jun 17 12:18:51 2020
    On Wed, 17 Jun 2020 04:38:15 -0700, Eric Douglas wrote:

    Here's a simple sample that reproduces what my app is doing.
    If it matters, I am running JRE 11.0.7_10 from AdoptOpenJDK If I scroll
    down and back up, the text on my table disappears. It reappears if I
    click on the table.

    Works fine here (scrolls up and down, nothing getting blanked when its
    scrolled back into view.

    Compiled and run with:

    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

    running on

    Linux version 5.6.16-200.fc31.x86_64 (mockbuild@bkernel03.phx2.fedoraproject.org)
    (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC))

    All I added to your code to get it to compile is:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Eric
    {

    /* --- your code here --- */

    }


    --
    Martin | martin at
    Gregorie | gregorie dot org

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eric Douglas@21:1/5 to Martin Gregorie on Wed Jun 17 06:08:00 2020
    On Wednesday, June 17, 2020 at 8:19:00 AM UTC-4, Martin Gregorie wrote:
    Works fine here (scrolls up and down, nothing getting blanked when its scrolled back into view.

    Compiled and run with:

    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

    running on

    Linux version 5.6.16-200.fc31.x86_64 (mockbuild@bkernel03.phx2.fedoraproject.org)
    (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC))

    All I added to your code to get it to compile is:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Eric
    {

    /* --- your code here --- */

    }


    Normally the JScrollPane puts a line around the table, I got around that like: t1.setBorder(LineBorder.createBlackLineBorder());

    It appears I'm running into this bug: https://bugs.openjdk.java.net/browse/JDK-8201309

    If I change the
    p4.add(t1);

    to:
    p4.add(new JScrollPane(t1);

    you can see scrolling down and back up still views the table fine, but the table is much bigger for some reason. I need to add some methods to resize it back to what it was if I need to wrap it in another JScrollPane like that.
    Using the Windows zip file v11 hotspot: https://adoptopenjdk.net/releases.html

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eric Douglas@21:1/5 to Martin Gregorie on Wed Jun 17 05:43:38 2020
    On Wednesday, June 17, 2020 at 8:19:00 AM UTC-4, Martin Gregorie wrote:
    Works fine here (scrolls up and down, nothing getting blanked when its scrolled back into view.

    Compiled and run with:

    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

    running on

    Linux version 5.6.16-200.fc31.x86_64 (mockbuild@bkernel03.phx2.fedoraproject.org)
    (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC))

    All I added to your code to get it to compile is:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Eric
    {

    /* --- your code here --- */

    }


    Looks fine here as well, I just compiled it with Java 8, problem must be specific to Java 11.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Martin Gregorie@21:1/5 to Eric Douglas on Wed Jun 17 13:08:38 2020
    On Wed, 17 Jun 2020 05:43:38 -0700, Eric Douglas wrote:

    On Wednesday, June 17, 2020 at 8:19:00 AM UTC-4, Martin Gregorie wrote:
    Works fine here (scrolls up and down, nothing getting blanked when its
    scrolled back into view.

    Compiled and run with:

    openjdk version "1.8.0_252"
    OpenJDK Runtime Environment (build 1.8.0_252-b09)
    OpenJDK 64-Bit Server VM (build 25.252-b09, mixed mode)

    running on

    Linux version 5.6.16-200.fc31.x86_64
    (mockbuild@bkernel03.phx2.fedoraproject.org)
    (gcc version 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC))

    All I added to your code to get it to compile is:

    import java.awt.*;
    import javax.swing.*;
    import javax.swing.table.*;
    public class Eric {

    /* --- your code here --- */

    }


    Looks fine here as well, I just compiled it with Java 8, problem must be specific to Java 11.

    Yep. When it worked OK here I thought that might be the case. If there's
    an accessable bug list for 11 it would be worth a quick scan and a bug
    report if its not a known bug.


    --
    Martin | martin at
    Gregorie | gregorie dot org

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Eric Douglas@21:1/5 to Eric Douglas on Wed Jun 17 08:07:51 2020
    On Wednesday, June 17, 2020 at 9:08:10 AM UTC-4, Eric Douglas wrote:
    you can see scrolling down and back up still views the table fine, but the table is much bigger for some reason. I need to add some methods to resize it back to what it was if I need to wrap it in another JScrollPane like that.
    Using the Windows zip file v11 hotspot: https://adoptopenjdk.net/releases.html

    ok, I found the workaround. https://stackoverflow.com/questions/13213645/set-size-of-jtable-in-jscrollpane-and-in-jpanel-with-the-size-of-the-jframe

    so now it's


    public static void main(String[] args) {

    EventQueue.invokeLater(() -> {
    JFrame win1 = new JFrame();
    Container p1 = win1.getContentPane();
    JPanel p2 = new JPanel();
    JPanel p3 = new JPanel();
    JPanel p4 = new JPanel();
    JPanel p5 = new JPanel();
    JPanel p6 = new JPanel();
    JPanel p7 = new JPanel();
    p5.add(p4);
    p6.add(p5);
    p7.add(p6);
    JScrollPane sp1 = new JScrollPane(p7);
    p1.add(p2);
    p2.add(p3);
    p3.add(sp1);
    win1.setPreferredSize(new Dimension(640,480));
    Object[][] data = new String[][] {{"data1"},{"data2"},{"data3"}};
    String[] cols = new String[] {"col1"};
    DefaultTableModel model = new DefaultTableModel(data,cols);
    JTable t1 = new JTable(model);
    p4.setLayout(new BoxLayout(p4, BoxLayout.PAGE_AXIS));
    JScrollPane sp2 = new JScrollPane(t1);
    t1.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    t1.setPreferredScrollableViewportSize(t1.getPreferredSize());
    t1.setFillsViewportHeight(true);
    p4.add(sp2);
    t1.setTableHeader(null);
    sp2.setBorder(null);
    for (int i = 0; i < 10; i++) {
    p4.add(new JLabel("Label " + i));
    }
    sp1.setPreferredSize(new Dimension(150,150));

    win1.setSize(new Dimension(800,600));
    win1.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    win1.setVisible(true);
    });

    }
    and yes all basic JRE imports
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.EventQueue;

    import javax.swing.BoxLayout;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTable;
    import javax.swing.WindowConstants;
    import javax.swing.table.DefaultTableModel;

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)