🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.jbuilder.java.swing
Article #7506

Re: JTable scrolling related question

#7506
From: Hartmut
Date: Mon, 15 Jan 2001 16:21
85 lines
3749 bytes
Torsten,

no, the filling of the tabel occurs not in that own thread,
but in the ActionPerformed-Handler of a JButton.

Only because of that scrolling problem I tried my first thread.

Thank you for your warning.
You're right, it is a hack, not a solution.

But obviously, without own threads at all, things behave like this:
while the table model is still being filled,
either the JTable or the JScrollPane makes already a decision about the
position of the last row,
and doesn't revide that decision afterwards, after the model's filling is
completed.

Thank you for the SUN-link.
I read the passage about "Using the invokeLater() Method".
I found the class EventQueue a tried its static method invokeLater():
Instead of my own thread, at the very same code position, where the
scrolling should come,
I call my Runnable with
java.awt.EventQueue.invokeLater( myRunnableScroll );
Also the run-method is now without the 'sleep( 500 )'.

Is it right that this posts myRunnableScroll's run-method at the end of the
EventQueue of the AWTEventDispatchThread?
(This is the only thread I have now, isn't it?)

This way it seems to work correctly.

Could this be a real "solution" now?

I appreciate your opinion!

Hartmut


PS:
My stripped-out example:
----------------------------------------------------------------------------
-----
 void jButtonScrolltest_actionPerformed(ActionEvent e)
 {
  // delete all rows of the table
  for( int row = tableModel.getRowCount() - 1; row >= 0; row-- )
   tableModel.removeRow( row );

  String[] content = new String[ 3 ];

  // column titles
  content[ 0 ] = "Field_A";
  content[ 1 ] = "Field_B";
  content[ 2 ] = "Field_C";
  tableModel.setColumnIdentifiers( content );

  for( int index = 0; index < 400; index++ )
  {
   content[ 0 ] = "A_" + index;
   content[ 1 ] = "B_" + index;
   content[ 2 ] = "C_" + index;
   tableModel.addRow( content );
  }

  // scroll table to last row

  /* tip from Greg Hamer */
  jScrollPaneTable.getViewport().scrollRectToVisible( jTable.getCellRect(
    jTable.getRowCount(), 0, true ) );

  /*
  Scroll myRunnableScroll = new Scroll( jTable, jScrollPaneTable );
  java.awt.EventQueue.invokeLater( myRunnableScroll );
  */
 }
----------------------------------------------------------------------------
-----

JScrollPane jScrollPaneTable contents JTable jTable.
This version gets the scroll problem.

If I activate myRunnableScroll - Scroll.run() simply does the call
jScrollPaneTable.getViewport()...
with the arguments transmitted by the constructor - the scrolling works.
Technical Details
Message-ID: <3a632376_1@dnews>
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!hermes.visi.com!news-out.visi.com!news.tele.dk!204.71.34.15!news-out.cwix.com!newsfeed.cwix.com!europa.netcrusader.net!204.127.161.3!wn3feed!worldnet.att.net!164.128.36.58!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!62.227.122.87
References: <3A1583E1.8FD78A76@netrisk.com> <3a15c300_2@dnews> <3a5c6686_2@dnews> <MPG.14c70100271fd34c989e6f@forums.borland.com> <3a62fa9f_1@dnews> <3a630ad3$1_2@dnews>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 111d45,1fc5e943f0feb2d4
X-Google-Attributes: gid111d45,public
X-Google-ArrivalTime: 2001-01-15 08:32:05 PST
From: "Hartmut" <hartmut.kiessling@bnhof.de>
Newsgroups: borland.public.jbuilder.java.swing
References: <3A1583E1.8FD78A76@netrisk.com> <3a15c300_2@dnews> <3a5c6686_2@dnews> <MPG.14c70100271fd34c989e6f@forums.borland.com>  <3a62fa9f_1@dnews>  <3a630ad3$1_2@dnews>
Subject: Re: JTable scrolling related question
Date: Mon, 15 Jan 2001 17:21:45 +0100
Lines: 88
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 5.50.4133.2400
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
NNTP-Posting-Host: 62.227.122.87
Message-ID: <3a632376_1@dnews>
X-Trace: 15 Jan 2001 08:21:10 -0800, 62.227.122.87
Path: arc1-ca.pugleaf.net!supernews.google.com!sn-xit-03!supernews.com!hermes.visi.com!news-out.visi.com!news.tele.dk!204.71.34.15!news-out.cwix.com!newsfeed.cwix.com!europa.netcrusader.net!204.127.161.3!wn3feed!worldnet.att.net!164.128.36.58!newsfeed-zh.ip-plus.net!news.ip-plus.net!bornews.borland.com!dnews!62.227.122.87