JButton Hellp [英] JButton Hellp

查看:103
本文介绍了JButton Hellp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想设置Jbutton的背景颜色。我知道做这种事情的正常方法是以下方式:


JButton button = new JButton(" xxxx");

button .setBackground(Color.RED);


但在我的程序中我按以下方式添加我的Jbutton ..


horizo​​ntalBox2 = Box.createHorizo​​ntalBox ();

horizo​​ntalBox2.add(新JButton(黑色));


所以如何设置此按钮的背景颜色说黑...任何帮助,将不胜感激。谢谢。

So I want to set the background color of a Jbutton. I know that the normal way to do such a thing is down the following way:

JButton button = new JButton("xxxx");
button.setBackground(Color.RED);

but in my program i add my Jbutton the following way..

horizontalBox2=Box.createHorizontalBox();
horizontalBox2.add(new JButton("Black"));

so how would i go about setting the background color of this button to say black??? Any help would be appreciated. Thanks.

推荐答案

@ yeshello54


这只是编程:您需要亲自引用该按钮,以便您可以设置其背景颜色:

@yeshello54
That is just programming: you need to have a reference to that button yourself so you can set its background colour:

展开 | 选择 | Wrap | 行号


请使用这些代码标签。文字是这样的:


[代码]

你的文字在这里...

[/ code]


将显示如下:

And please do use those code tags. Text like this:

[code]
your text here ...
[/code]

will display like this:

展开 | 选择 | Wrap | 行号


@JASAH


实际上这就是他所说的。还有另外一种方法:

@JosAH
Actually that was what he was telling. There is another way though:

展开 | 选择 | Wrap | 行号


这篇关于JButton Hellp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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