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


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

How to scroll a table wit

From "Gregory Miecznik" <gregory.miecznik@THRWHITE.remove-dii-this>
Subject How to scroll a table wit
Message-ID <1194455949.318245.179690@o3g2000hsb.googlegroups.com> (permalink)
Newsgroups comp.lang.java.gui
Date 2011-04-27 15:40 +0000
Organization TDS.net

Show all headers | View raw


  To: comp.lang.java.gui
My question is related to a typical example in a spreadsheet where I
can have an arbitrary component ontop of a scrollable table, which
should scroll along with the table.
The position of the overlaid component is arbitrary. A typical example
would be a
spreadsheet table with a graphical bar.

The only way I managed to achive it with some success is by creating a
scrollable table first,
then adding the scrollable table and my additional component to the
contentPane, which
has no layout manager, as in the code below:
----------------------------------------------------------------------------
// (1) Get the content pane from a JFrame
Container pane = myFrame.getContentPane();

// (2) Create a custom table with a header column
JTable jt = JTableCustom;
JTable jh = HeaderColumn;

// (3) Create a JScrollPane pane for this table
JScrollPane scrollPane = new JScrollPane();

// (4) Add the table to the scroll pane
JViewport jv = new JViewport();
jv.setView(jh);
jv.setPreferredSize(jh.getMaximumSize());
scrollPane.setViewportView(jt);
scrollPane.setRowHeader(jv);                // Now I have a properly
scrollable table

// (5) Create an arbitrary JComponent and put it somehere ontop of the
table
JLabel label = new JLabel("A Label");
label.setBounds(200,200,200,200);

// (6) Add the scrollable table an my label to the pane
pane.add(label);
pane.add(scrollPane);
------------------------------------------------------------------------------------------------

This solution has only one problem - when I scroll pas the position of
my label (the label
scrolls nicely with the table),and then scroll back to where the label
was, the label does not repaint itself automatically - I have to
slightly change the window size to get the label to
reappear.

An obvious solution is to add a mouse listener and detect when I need
to repaint the label
but it is not a clean way to do it.

Do you know a propper way to do it? (I have tried various methods,
including a LayeredPane,
or adding  a customized JPanel with the table and the label to the
viewPort, but this is the only
one that works reasonably well)

Thanks,
Gregory Miecznik

---
 * 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 | NextNext in thread | Find similar | Unroll thread


Thread

How to scroll a table wit "Gregory Miecznik" <gregory.miecznik@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000
  Re: How to scroll a table a24900@googlemail.com.remove-dii-this - 2011-04-27 15:40 +0000
    Re: How to scroll a table "Gregory Miecznik" <gregory.miecznik@THRWHITE.remove-dii-this> - 2011-04-27 15:40 +0000

csiph-web