user2771738
user2771738

Reputation: 951

JScrollPane in JTables

I wonder if you guys had problem such if you got some JPanel which got his own JScrollPane and in your panel you are using a lot of JTables with their own JScrollPanes, there is a problem to scroll up/down your panel?

I mean when your mouse is on viewport of some table, then JScrollPane of JTable is listening on scroll, so when I got many JTables I am able to scroll only in a few places of the panel, it's so annoying...

Are there some functions which will send my scroll event to parent JPanel JScrollPane when the JTable scroll is even not shown? I mean I want to disable JScrollPane whenever some JTable don't need to use scroll (when it is hidden, cause there are too less records).

Upvotes: 1

Views: 241

Answers (1)

trashgod
trashgod

Reputation: 205875

Yes, JTable understands several named scrolling actions, listed below. They are normally used in key bindings, but you can evoke them yourself, as shown in this related example that commandeers the actions defined for a scroll pane.

Addendum: In outline, get the named action from the component's action map:

Action action = table.getActionMap().get(name);

Evoke the action by name when needed:

action.actionPerformed(new ActionEvent(table, 0, name));

Scrolling related action names for JTable:

scrollDownChangeSelection
scrollDownExtendSelection
scrollLeftChangeSelection
scrollLeftExtendSelection
scrollRightChangeSelection
scrollRightExtendSelection
scrollUpChangeSelection
scrollUpExtendSelection

Upvotes: 3

Related Questions