Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.java.gui > #1307 > unrolled thread
| Started by | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| First post | 2011-04-27 15:32 +0000 |
| Last post | 2011-04-27 15:32 +0000 |
| Articles | 11 — 4 participants |
Back to article view | Back to comp.lang.java.gui
Horizontally scrolling JT "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> - 2011-04-27 15:32 +0000
Re: Horizontally scrollin swapnonil@gmail.com.remove-dii-this - 2011-04-27 15:32 +0000
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Horizontally scrolling JT |
| Message-ID | <460a32a4$0$27120$db0fefd9@news.zen.co.uk> |
To: comp.lang.java.gui
I am unable to make my JTable/JScrollPane so that it gains horizontal
scrollbars when container width < JTable min width.
Any suggestions?
SSCCE
-----------------------------------8<---------------------------------
import java.awt.BorderLayout;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableColumn;
public class HorizScrollTable extends JPanel {
HorizScrollTable() {
setLayout(new BorderLayout());
JTable table = new JTable(data, headings);
// table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); // [1]
for (int i = 0; i < headings.length; i++) {
TableColumn column = table.getColumnModel().getColumn(i);
int width = widths[i];
column.setPreferredWidth(width);
column.setMinWidth(width); // [2]
}
// JPanel p = new JPanel(new BorderLayout());
// p.add(table, BorderLayout.CENTER); // [3]
JScrollPane scrollPane = new JScrollPane(table);
// scrollPane.setHorizontalScrollBar(new JScrollBar()); // [4]
add(scrollPane, BorderLayout.CENTER);
}
String[] headings = new String[] { "Product Category", "Product",
"Supplier", "Region", "Year", "Period", "Sales" };
int[] widths = { 80, 100, 200, 120, 40, 80, 60 };
Object[][] data = {
{ "Apples", "Granny Smith",
"The Freemantle apple collective",
"Northeast", 2007, "Quarter 2", 156.67 },
{ "Apples", "Granny Smith",
"The Freemantle apple collective",
"South", 2007, "Quarter 2", 1766.01 },
{ "Pears", "Concord", "John Williams and Sons",
"Northeast",
2007, "Quarter 2", 987.29 },
{ "Pears", "Conference", "Montpelier et fils",
"South", 2007,
"Quarter 2", 1221.16 } };
private static void createAndShowGUI() {
JFrame frame = new JFrame("Horizontally scrollable JTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new HorizScrollTable();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
/*
* Note 1: Causes horiz scroll bar when frame shrunk but
* columns can't grow.
* Note 2: Prevent columns shrinking too far when frame shrunk
* using mouse
* Note 3: H.Scrollbar :-) Height :-) No headings :-( Width :-(
* Note 4: Has no effect.
*/
-----------------------------------8<---------------------------------
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175075823.635398.208650@n59g2000hsh.googlegroups.com> |
| In reply to | #1307 |
To: comp.lang.java.gui
On Mar 28, 7:17 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
wrote:
> I am unable to make my JTable/JScrollPane so that it gains horizontal
> scrollbars when container width < JTable min width.
>
> Any suggestions?
>
> SSCCE
> -----------------------------------8<---------------------------------
> import java.awt.BorderLayout;
...
> public class HorizScrollTable extends JPanel {
>
> HorizScrollTable() {
> column.setPreferredWidth(width);
> column.setMinWidth(width); // [2]
> }
JPanel p = new JPanel(new BorderLayout());
p.add(table, BorderLayout.CENTER); // [3]
// new ..
p.setPreferredSize( table.getPreferredSize() );
JScrollPane scrollPane = new JScrollPane( p );
....
Andrew T.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <460a6d4b$0$22523$fa0fcedb@news.zen.co.uk> |
| In reply to | #1308 |
To: comp.lang.java.gui
Andrew Thompson wrote:
> On Mar 28, 7:17 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
> wrote:
>
>> I am unable to make my JTable/JScrollPane so that it gains horizontal
>> crollbars when container width < JTable min width.
>>
>> Any suggestions?
>>
>> SSCCE
>> -----------------------------------8<---------------------------------
>> import java.awt.BorderLayout;
>
> ...
>
>> public class HorizScrollTable extends JPanel {
>>
>> HorizScrollTable() {
>
>
>> column.setPreferredWidth(width);
>> column.setMinWidth(width); // [2]
>> }
>
>
> JPanel p = new JPanel(new BorderLayout());
> p.add(table, BorderLayout.CENTER); // [3]
> // new ..
> p.setPreferredSize( table.getPreferredSize() );
> JScrollPane scrollPane = new JScrollPane( p );
> ....
Thanks, that is perfect in all but one respect ...
Unfortunately the table headings no longer show.
In case I've misread your message, here is my revised constructor:
HorizScrollTable() {
setLayout(new BorderLayout());
JTable table = new JTable(data, headings); // headings!
for (int i = 0; i < headings.length; i++) {
TableColumn column = table.getColumnModel().getColumn(i);
int width = widths[i];
column.setPreferredWidth(width);
column.setMinWidth(width);
}
JPanel p = new JPanel(new BorderLayout());
p.add(table, BorderLayout.CENTER);
p.setPreferredSize(table.getPreferredSize());
JScrollPane scrollPane = new JScrollPane(p);
add(scrollPane, BorderLayout.CENTER);
}
(new readers please see first posting in thread for original SSCCE in full)
Is it impossible to have horizontal scrolling AND headings?
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175161358.541862.110160@n76g2000hsh.googlegroups.com> |
| In reply to | #1309 |
To: comp.lang.java.gui On Mar 28, 11:27 pm, RedGrittyBrick <redgrittybr...@spamweary.foo> wrote: .. > Thanks, that is perfect in all but one respect ... > Unfortunately the table headings no longer show. I am beginning to think this is a bug, and have started trawling through the bug D/B looking for similar problems. Unfortunately searching the Bug D/B is horrendously slow from Australia (or maybe it is just horrendously slow from anywhere?) and I have yet to see any bug report that is closely related. As an aside. That was a damn fine SSCCE, I wish I'd put a little more effort into reading your comments before I opened my big mouth in that first post. Could have saved us all some bandwidth. ;-) Andrew T. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <460b98f3$0$10735$db0fefd9@news.zen.co.uk> |
| In reply to | #1311 |
To: comp.lang.java.gui Andrew Thompson wrote: > On Mar 28, 11:27 pm, RedGrittyBrick <redgrittybr...@spamweary.foo> > wrote: .. > >> Thanks, that is perfect in all but one respect ... Unfortunately >> the table headings no longer show. > > > I am beginning to think this is a bug, and have started trawling > through the bug D/B looking for similar problems. Unfortunately > searching the Bug D/B is horrendously slow from Australia (or maybe > it is just horrendously slow from anywhere?) and I have yet to see > any bug report that is closely related. Thanks, I've no experience of the Java bug database but I'll try to find out about it and do a search from here (probably no faster than from Oz) > As an aside. That was a damn fine SSCCE, I wish I'd put a little > more effort into reading your comments before I opened my big mouth > in that first post. Could have saved us all some bandwidth. ;-) I'm grateful that at least one experienced Java programmer has looked at my problem and certainly don't regard the bandwidth as wasted :-) If you think it may be a bug then I can think about stopping tearing my hair out and worrying about what I am doing wrong. That's a good result. Thanks. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175168444.816844.44770@n76g2000hsh.googlegroups.com> |
| In reply to | #1313 |
To: comp.lang.java.gui
On Mar 29, 8:46 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
wrote:
> Andrew Thompson wrote:
> > On Mar 28, 11:27 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
> > wrote: ..
>
> >> Thanks, that is perfect in all but one respect ... Unfortunately
> >> the table headings no longer show.
>
> > I am beginning to think this is a bug, and have started trawling
> > through the bug D/B looking for similar problems.
Here is a likely looking one, though Sun
marked it 'Closed, not a bug' (shrugs). *
<http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4194022>
> Thanks, I've no experience of the Java bug database
Start here..
<http://bugs.sun.com/bugdatabase/index.jsp>
> If you think it may be a bug
Unfortunately, Sun doesn't. ;-)
>..then I can think about stopping tearing my
> hair out and worrying about what I am doing wrong.
* OTOH, using a slight variant of the advice
on that page, I came up with this (very
hackish looking) code that seems to behave
as we might expect..
<sscce>
import java.awt.*;
import javax.swing.*;
import javax.swing.table.TableColumn;
public class HorizScrollTable extends JPanel {
HorizScrollTable() {
setLayout(new BorderLayout());
JTable table = new JTable(data, headings){
Component parent;
public boolean getScrollableTracksViewportWidth(){
return isThinnerThanParent();
}
boolean isThinnerThanParent() {
if (parent==null) {
parent = getParent();
}
Dimension d1 = getSize();
Dimension d2 = parent.getSize();
return (d1.width<=d2.width);
}
};
table.setAutoResizeMode(
JTable.AUTO_RESIZE_ALL_COLUMNS);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane, BorderLayout.CENTER);
}
String[] headings = new String[] { "Product Category", "Product",
"Supplier", "Region", "Year", "Period", "Sales" };
int[] widths = { 80, 100, 200, 120, 40, 80, 60 };
Object[][] data = {
{ "Apples", "Granny Smith",
"The Freemantle apple collective",
"Northeast", 2007, "Quarter 2", 156.67 },
{ "Apples", "Granny Smith",
"The Freemantle apple collective",
"South", 2007, "Quarter 2", 1766.01 },
{ "Pears", "Concord", "John Williams and Sons",
"Northeast",
2007, "Quarter 2", 987.29 },
{ "Pears", "Conference", "Montpelier et fils",
"South", 2007,
"Quarter 2", 1221.16 } };
private static void createAndShowGUI() {
JFrame frame = new JFrame("Horizontally scrollable JTable");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JComponent newContentPane = new HorizScrollTable();
newContentPane.setOpaque(true);
frame.setContentPane(newContentPane);
frame.pack();
frame.setSize(300,300);
frame.setVisible(true);
}
public static void main(String[] args) {
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
}
</sscce>
Does that work for you?
Andrew T.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <460bc259$0$19252$da0feed9@news.zen.co.uk> |
| In reply to | #1315 |
To: comp.lang.java.gui
Andrew Thompson wrote:
> RedGrittyBrick wrote:
>> Andrew Thompson wrote:
>>> RedGrittyBrick wrote: ..
>>
>>>> Thanks, that is perfect in all but one respect ... Unfortunately
>>>> the table headings no longer show.
>>
>>> I am beginning to think this is a bug, and have started trawling
>>> through the bug D/B looking for similar problems.
>
> Here is a likely looking one, though Sun
> marked it 'Closed, not a bug' (shrugs). *
> <http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4194022>
>
> using a slight variant of the advice
> on that page, I came up with this (very
> hackish looking) code that seems to behave
> as we might expect..
>
<snip SSCCE head>
> HorizScrollTable() {
> setLayout(new BorderLayout());
> JTable table = new JTable(data, headings){
> Component parent;
>
> public boolean getScrollableTracksViewportWidth(){
> return isThinnerThanParent();
> }
>
> boolean isThinnerThanParent() {
> if (parent==null) {
> parent = getParent();
> }
> Dimension d1 = getSize();
> Dimension d2 = parent.getSize();
>
> return (d1.width<=d2.width);
> }
> };
> table.setAutoResizeMode(
> JTable.AUTO_RESIZE_ALL_COLUMNS);
> JScrollPane scrollPane = new JScrollPane(table);
>
> add(scrollPane, BorderLayout.CENTER);
> }
<snip SSCCE tail>
> Does that work for you?
Thanks Andrew, yes that works the way I wanted.
Before I read your latest posting I'd also been hunting in the bugs
database as you suggested ...
Searching Sun's Bug database led me (eventually) to Bug 4127936 reported
10-APR-1998 and marked "In progress, bug", "Evaluation: ... needs to be
fixed before FCS with JDK1.2." :-o
There are several suggested workarounds in the commentary. For future
readers of this thread: apart the workaround which Andrew found (see
above), another workaround that I tried was ...
...
scrollPane.addComponentListener(new
CorrectStrangeBehaviourListener(table, scrollPane));
...
/**
*
* @author dbeutner 16-MAY-2002
* See Sun Java bug report 4127936.
* Amended 29/3/2007 by RedGrittyBrick to add
* constructor with parameters
*
*/
private class CorrectStrangeBehaviourListener
extends ComponentAdapter {
private JTable table;
private JScrollPane scrollPane;
CorrectStrangeBehaviourListener(JTable table,
JScrollPane scrollPane) {
this.table = table;
this.scrollPane = scrollPane;
}
public void componentResized(ComponentEvent e) {
if (table.getPreferredSize().width
<= scrollPane.getViewport()
.getExtentSize().width) {
table.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
} else {
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
}
}
}
The one Andrew found is shorter but since I have several tables it may
be worth me putting the bulk of the workaround code into a separate
class as the above example does.
Thanks again Andrew.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Andrew Thompson" <andrew.thompson@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175222599.679984.52940@p15g2000hsd.googlegroups.com> |
| In reply to | #1317 |
To: comp.lang.java.gui On Mar 29, 11:42 pm, RedGrittyBrick <redgrittybr...@spamweary.foo> wrote: ... > Thanks again Andrew You're welcome. Glad you found a suitable resolution. And all this serves to remind me that ..uggh JTable makes my head hurt! ;-) Andrew T. --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175244380.730269.58280@y66g2000hsf.googlegroups.com> |
| In reply to | #1309 |
To: comp.lang.java.gui
On Mar 28, 3:27 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
wrote:
> Andrew Thompson wrote:
> > On Mar 28, 7:17 pm, RedGrittyBrick <redgrittybr...@spamweary.foo>
> > wrote:
>
> >> I am unable to make my JTable/JScrollPane so that it gains horizontal
> >> crollbars when container width < JTable min width.
>
> >> Any suggestions?
>
> >> SSCCE
> >> -----------------------------------8<---------------------------------
> >> import java.awt.BorderLayout;
>
> > ...
>
> >> public class HorizScrollTable extends JPanel {
>
> >> HorizScrollTable() {
>
> >> column.setPreferredWidth(width);
> >> column.setMinWidth(width); // [2]
> >> }
>
> > JPanel p = new JPanel(new BorderLayout());
> > p.add(table, BorderLayout.CENTER); // [3]
> > // new ..
> > p.setPreferredSize( table.getPreferredSize() );
> > JScrollPane scrollPane = new JScrollPane( p );
> > ....
>
> Thanks, that is perfect in all but one respect ...
> Unfortunately the table headings no longer show.
>
> In case I've misread your message, here is my revised constructor:
>
> HorizScrollTable() {
> setLayout(new BorderLayout());
> JTable table = new JTable(data, headings); // headings!
>
> for (int i = 0; i < headings.length; i++) {
> TableColumn column = table.getColumnModel().getColumn(i);
> int width = widths[i];
> column.setPreferredWidth(width);
> column.setMinWidth(width);
> }
>
> JPanel p = new JPanel(new BorderLayout());
> p.add(table, BorderLayout.CENTER);
> p.setPreferredSize(table.getPreferredSize());
> JScrollPane scrollPane = new JScrollPane(p);
>
> add(scrollPane, BorderLayout.CENTER);
> }
>
> (new readers please see first posting in thread for original SSCCE in full)
>
> Is it impossible to have horizontal scrolling AND headings?
By setting the header explicitly on the scrollPane you can have
headers:
scrollPane.setColumnHeaderView(table.getTableHeader());
Regards,
Bart
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | "RedGrittyBrick" <redgrittybrick@THRWHITE.remove-dii-this> |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <460cdecd$0$10727$db0fefd9@news.zen.co.uk> |
| In reply to | #1325 |
To: comp.lang.java.gui
Bart Cremers wrote:
> RedGrittyBrick wrote:
>> Andrew Thompson wrote:
>>> RedGrittyBrick wrote:
>>>>
>>>> I am unable to make my JTable/JScrollPane so that it gains horizontal
>>>> scrollbars when container width < JTable min width.
>>>>
>>>> Any suggestions?
>>>>
>>>> SSCCE
>>>
>>> ...
>>>
>>>> JPanel p = new JPanel(new BorderLayout());
>>>> p.add(table, BorderLayout.CENTER); // [3]
>>> // new ..
>>> p.setPreferredSize( table.getPreferredSize() );
>>> JScrollPane scrollPane = new JScrollPane( p );
>>> ...
>>
>> Thanks, that is perfect in all but one respect ...
>> Unfortunately the table headings no longer show.
>>
>> In case I've misread your message, here is my revised constructor:
>>
>> HorizScrollTable() {
>> setLayout(new BorderLayout());
>> JTable table = new JTable(data, headings); // headings!
>>
>> for (int i = 0; i < headings.length; i++) {
>> TableColumn column = table.getColumnModel().getColumn(i);
>> int width = widths[i];
>> column.setPreferredWidth(width);
>> column.setMinWidth(width);
>> }
>>
>> JPanel p = new JPanel(new BorderLayout());
>> p.add(table, BorderLayout.CENTER);
>> p.setPreferredSize(table.getPreferredSize());
>> JScrollPane scrollPane = new JScrollPane(p);
>>
>> add(scrollPane, BorderLayout.CENTER);
>> }
>>
>> (new readers please see first posting in thread for original SSCCE in full)
>>
>> Is it impossible to have horizontal scrolling AND headings?
>
>
> By setting the header explicitly on the scrollPane you can have
> headers:
>
> scrollPane.setColumnHeaderView(table.getTableHeader());
>
Thanks Bart, that works well.
I guess introducing a JPanel between JTable and JScrollPane still counts
as a workaround for bug 4127936, but it is the most unobtrusive
workaround of the ones I've tried. I'm not sure if workarounds in source
code for Swing bugs should be subtle and unobtrusive or big and obvious.
My thoughts are moving towards unobtrusive but with a big comment.
---
* Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet!
--- Synchronet 3.15a-Win32 NewsLink 1.92
Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [next] | [standalone]
| From | swapnonil@gmail.com.remove-dii-this |
|---|---|
| Date | 2011-04-27 15:32 +0000 |
| Subject | Re: Horizontally scrollin |
| Message-ID | <1175456952.152297.247710@n76g2000hsh.googlegroups.com> |
| In reply to | #1307 |
To: comp.lang.java.gui Just set table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF); to your JTable, and you should be fine. I also suggest you try out the new JXTable class from the swingx project. http://swinglabs.org/projects.jsp http://swinglabs.org/docs/components/JXTable/tutorial.jsp They have a nice feature that allow users to 1. Disable enable horizontal scrolling. 2. Pack all columns. 3. Show Hide columns. All this can be done via a button that sits on the top right hand corner of your JXTable. You have to just do this jxTable.setColumnControlVisible(true); --- * Synchronet * The Whitehouse BBS --- whitehouse.hulds.com --- check it out free usenet! --- Synchronet 3.15a-Win32 NewsLink 1.92 Time Warp of the Future BBS - telnet://time.synchro.net:24
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.java.gui
csiph-web