Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.programmer > #39507 > unrolled thread
| Started by | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| First post | 2020-06-17 04:38 -0700 |
| Last post | 2020-06-17 08:07 -0700 |
| Articles | 6 — 2 participants |
Back to article view | Back to comp.lang.java.programmer
Simple fix for JTable view? Eric Douglas <e.d.programmer@gmail.com> - 2020-06-17 04:38 -0700
Re: Simple fix for JTable view? Martin Gregorie <martin@mydomain.invalid> - 2020-06-17 12:18 +0000
Re: Simple fix for JTable view? Eric Douglas <e.d.programmer@gmail.com> - 2020-06-17 05:43 -0700
Re: Simple fix for JTable view? Martin Gregorie <martin@mydomain.invalid> - 2020-06-17 13:08 +0000
Re: Simple fix for JTable view? Eric Douglas <e.d.programmer@gmail.com> - 2020-06-17 06:08 -0700
Re: Simple fix for JTable view? Eric Douglas <e.d.programmer@gmail.com> - 2020-06-17 08:07 -0700
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-06-17 04:38 -0700 |
| Subject | Simple fix for JTable view? |
| Message-ID | <e3357895-0977-41fe-9560-38699321cc82o@googlegroups.com> |
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);
});
}
[toc] | [next] | [standalone]
| From | Martin Gregorie <martin@mydomain.invalid> |
|---|---|
| Date | 2020-06-17 12:18 +0000 |
| Message-ID | <rcd1nb$203$1@dont-email.me> |
| In reply to | #39507 |
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-06-17 05:43 -0700 |
| Message-ID | <25529440-a176-4097-b520-2d2e87ebc00fo@googlegroups.com> |
| In reply to | #39508 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Martin Gregorie <martin@mydomain.invalid> |
|---|---|
| Date | 2020-06-17 13:08 +0000 |
| Message-ID | <rcd4km$tq7$1@dont-email.me> |
| In reply to | #39509 |
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-06-17 06:08 -0700 |
| Message-ID | <33240685-a651-4af0-9849-10237f4fb7e5o@googlegroups.com> |
| In reply to | #39508 |
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
[toc] | [prev] | [next] | [standalone]
| From | Eric Douglas <e.d.programmer@gmail.com> |
|---|---|
| Date | 2020-06-17 08:07 -0700 |
| Message-ID | <883d864c-b318-437b-b774-d6b82555addco@googlegroups.com> |
| In reply to | #39510 |
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;
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.programmer
csiph-web