• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtable - distinguish a visible area

 
Martin Zdarsky
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a JFrame and in it a JTable. I'd like to know if there is another window above mine and if so I'd like to know which cells in the jtable are actually visible on the screen.
is there a way how to figure this out?

Thanks,
Martin
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martin Zdarsky:
I have a JFrame and in it a JTable. I'd like to know if there is another window above mine and if so I'd like to know which cells in the jtable are actually visible on the screen.
is there a way how to figure this out?


The short answer is no, there's no way to figure this out.

The long answer is there may be ways to get at it approximately. Why would your app need to know this? Do you need to know just Java windows, or do you need to know about native OS windows too?
 
Martin Zdarsky
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Basically, my data source is a piece of hardware connected throught a serial cable. This connection is very slow; it takes about 3 seconds to fetch current data which are constantly changing.

Now, there is a need to watch different resources through the same cable as well, so when you run two instances of my app then the refresh takes 6 second. Potencially, there is no limit of how many views on the resource there is going to be (within a reason).

So, I had an idea of refreshing just fields which are currently visible to speed everything up. After all, why waste resources when nobodu is going to see it.

I was interested in native windows. The real visibility for a user.
What is the diffucult way?

thanks,
Martin
 
Brian Cole
Author
Ranch Hand
Posts: 920
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Martin Zdarsky:
I had an idea of refreshing just fields which are currently visible to speed everything up. After all, why waste resources when nobodu is going to see it.



Well JTable already queries its TableModel for only the cells that
it thinks are visible. It will only call getValueAt() for cell's that
it decides need to be drawn. That would be once initially, then again
if a window that had been obscuring it goes away. But while the window
is still on top there shouldn't be a refresh unless some code triggers
one. (If the model fires TableCellUpdated then I believe it will refresh
the cell if it is showing in the scroll pane, even if a window above
is obscuring. Is that the problem you're having?)

I was interested in native windows. The real visibility for a user.
What is the diffucult way?


I was going to suggest something along the lines of keeping tabs on
the RepaintManager. This can give you an idea of what areas are visible,
but doesn't really help keep track of windows that might appear on top.
 
Martin Zdarsky
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, not really.

The problem is that my data are changing constantly and I need to know which data is useful(visible to user), then fetch it from my hardware and then call TableCellUpdated.

The trouble I am having is that I don't know what it is I want to fetch from data source.

If my data were static then JTable would do all I needed.

Maybe I want too much from java. It is after all, platform independent...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!