Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.java.gui > #1325

Re: Horizontally scrollin

From "Bart Cremers" <bart.cremers@THRWHITE.remove-dii-this>
Subject Re: Horizontally scrollin
Message-ID <1175244380.730269.58280@y66g2000hsf.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
References <460a6d4b$0$22523$fa0fcedb@news.zen.co.uk>
Date 2011-04-27 15:32 +0000
Organization TDS.net

Show all headers | View raw


  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

Back to comp.lang.java.gui | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

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

csiph-web