如何通过单击键盘箭头来更改图像?
我用java做了一个项目。现在在这个特定的模块中,我向用户展示,所以我向他们展示库存。
现在就开始这样做。
正如您将在屏幕截图中看到的那样[我已经放置了屏幕截图,以便您可以很好地理解]。
为了显示图像,我制作了一张表格,并在其中放置了标签,然后在标签处设置图标。
现在,只要用户单击任何图像,我就会将该图像放在大标签上。
但这在鼠标单击时效果很好,但客户希望如此,如果用户通过键盘箭头键导航,那么应该会发生同样的情况。
含义:用户通过键盘导航,然后它应该反映在该表上[用户应该知道当前选择的表],然后一旦用户通过键盘箭头事件导航,然后单击 Enter,那么该图像应该反映在大标签上。
这是该屏幕截图的链接。
I have made one project in java. Now in this particular module, i am showing the user , so i am showing them a stock inventory.
Now for doing this.
As you will see in the screen shot [ i have put screenshot so you can understand well ].
To show the images , i have made one table and i have put labels in that and then i am setting the icon at the label.
Now as soon as user click on the any image, then that image i put on big label.
But this works perfect on mouse click but client want that , if user navigate the by keyboard arrow keys then in same should be happen.
Means : User navigate by key board then it should reflect on that table [user should know that which is currently seleted ] and then as soon as the user navigate by key board arrow events and then click enter then that image should reflect on big label.
Here is the Link for that screenshot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来您需要做的事情有两个步骤。
首先,用户需要知道选择了哪个图像。不幸的是,我无法帮助您,因为我不知道您如何显示该网格。从用户界面的角度来看,我建议利用每个单元格中的白色边框 - 将其更改为黑色、蓝色或任何您喜欢的颜色以表明它是选定的单元格。您似乎正在使用 JTable,在这种情况下您可以编写 TableCellRenderer (可能通过扩展 DefaultTableCellRenderer) 并调用其 setBackground() 方法。
然后你需要监听键盘输入。这部分应该不会太糟糕;编写 KeyListener 并将其添加到 JTable 本身。对于每个按键事件,查看按键代码是否与方向键匹配;如果是这样,请相应地移动光标。不要忘记留意 JTable 的边缘。
Sounds like there are two steps in what you need to do.
First, the user needs to know which image is selected. Unfortunately I can't help you with that, since I don't know how you're displaying that grid. From a UI point of view, I'd suggest exploiting that white border you've got in each cell -- change it black, blue, or whatever color you like to indicate that it's the selected cell. You seem to be using a JTable, in which case you can write a TableCellRenderer (probably by extending DefaultTableCellRenderer) and call its setBackground() method.
Then you need to listen for keyboard input. This part shouldn't be too bad; write a KeyListener and add it to the JTable itself. For each key event, see if the key code matches the arrow keys; if so, move your cursor around accordingly. Don't forget to watch out for the edges of the JTable.