Skip to main content

Wrapping a JTable in a JXLayer stops the Page Up and Page Down keys from working.

1 reply [Last post]
boomah
Offline
Joined: 2007-07-13
Points: 0

If I wrap a JTable in a JXLayer and then add the layer to a scroll pane, everything works as expected apart from when I try to Page Up or Page Down.

Nothing happens.

Is this a bug or do I need to add something else to the layer?

Thanks, Nick.

Edit:

Looking into the code, I see in BasicTableUI there is a check on line 406 (java 6 update 24) that goes:

if (!(table.getParent().getParent() instanceof JScrollPane)) {return;}

and this is what is causing the problem. Ouch, I guess I'll have to define my own action.

Edit2:

Looking at the source for JDK 7 I see the same code is there as well. This means it won't work with the JLayer component.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
boomah
Offline
Joined: 2007-07-13
Points: 0

OK, as this turns out to be not a JXLayer problem there's no point answering here. I'm going to file a bug against Java 7 and see what happens.

For anyone who might come across this, here is how I got around it: (code is in scala but same goes for java)

override the getParent method on your JTable like so:

{code}

val className = "javax.swing.plaf.basic.BasicTableUI$Actions"

val methodName = "actionPerformed"

override def getParent:Container = {

val stackElement = Thread.currentThread().getStackTrace()(2)

if (stackElement.getClassName == className && stackElement.getMethodName == methodName) {

super.getParent.getParent

} else {

super.getParent

}

{code}

nasty hack which I'm quite proud of... not done one of those for a long time :)