把JPanel1设为JScrollPane的ViewPort,在JPanel1上添加了JPanel2,
JPanel1的布局设为绝对布局,当JPanel2获得焦点的时候,
我按键盘上下左右键,滚动条滚动了,而JPanel2并没有获得键盘事件,
如果我想让JPanel2获得键盘事件,并且JScrollPane不滚动,我应该怎么做,
谢谢
6 个解决方案
#1
JPanel有键盘事件呀
#2
+1 添加键盘事件。
#3
JPanel2.addActionListener(new KeyAdapter(){})
#4
修改下,是addKeyListener
#5
The method addKeyListener(MyPanel) is undefined for the type MyPanel
#6
+1
#1
JPanel有键盘事件呀
#2
+1 添加键盘事件。
#3
JPanel2.addActionListener(new KeyAdapter(){})
#4
修改下,是addKeyListener
#5
The method addKeyListener(MyPanel) is undefined for the type MyPanel
#6
+1