在 jButton 中添加背景(netbeans gui builder) [英] Adding background in jButton (netbeans gui builder)

查看:29
本文介绍了在 jButton 中添加背景(netbeans gui builder)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试通过转到其属性然后转到图标在 Java 中的 Jbutton 中添加背景时,它然后设置按钮的背景,但我在按钮上写的文本,它向右移动(在按钮区域之外).对此有什么解决方案?

When i try to add background in Jbutton in java by going to its properties and then icon, it then sets the background of the button but the text which i have written on the button,it moves right(outside the button area).What is the solution for this?

推荐答案

据我所知,您不是在设置背景,而是通过此将图标设置为按钮.这就是为什么您在右侧看到图像而在左侧看到文本的原因.要将图像作为背景添加到按钮,您需要覆盖 JButonpaintComponent(g) 方法并在其中绘制图像.

As far as I understand you are not setting background but you are setting Icon to button by this. And that is why you see Image on right side and text on left side. To add image as background to button you need to override paintComponent(g) method of JButon and draw your image in it.

这篇关于在 jButton 中添加背景(netbeans gui builder)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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