JLabel提供的ImageIcon示例,具有绝对定位 [英] ImageIcon by JLabel example with absolute positioning

查看:224
本文介绍了JLabel提供的ImageIcon示例,具有绝对定位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了很多示例代码,但是没有一个示例代码专门向我展示如何通过在JFrame上使用JLabel而不使用布局管理器来显示ImageIcon.我一再被告知,绝对定位比布局管理器麻烦且效率低,但我更希望完全控制元素的行进方向.一个JLabel的全尺寸示例类(不添加任何额外的东西),它将在JFrame上以绝对定位显示图像,非常感谢,谢谢

I have seen a lot of example code but none that specifically shows me how to display an ImageIcon through the use of a JLabel on a JFrame without using a layout manager. I am repeatedly told that absolute positioning is a hassle and less efficient than a layout manager but I'd prefer complete control over where my elements are going. A full scale example class (with no extra things added) of a JLabel that will display an image on a JFrame with absolute positioning would be much appreciated, thank you

推荐答案

我需要的图像必须在屏幕上四处移动

The image I need has to move around the screen

原始问题中缺少的重要信息.我对此使用null布局没有问题.

An important piece of information missing in the original question. I don't have a problem using a null layout for this.

我想用屏幕上的箭头键四处移动吗?

I wanted to move around with arrow keys on the screen?

请勿为此使用KeyListener.相反,您应该使用按键绑定.

And don't use a KeyListener for this. Instead you should be using Key Bindings.

请参见使用键盘为该问题提供了一种解决方案.

See the KeyboardAnimation.java code found in Motion Using the Keyboard for one solution to this problem.

这篇关于JLabel提供的ImageIcon示例,具有绝对定位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆