set a icon for JRadioButton

liaomingxue 2003-10-04 10:42:14
Sorry,Chinese Input failed!!!!!!!!!!!

Set a icon for a JRadioButton component meeting the following:
1: a icon including
2: text excluded
and keeing radiobutton's original round check box to indicate whether checked or not.

High score is available for good answer
...全文
85 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
liad 2003-10-07
  • 打赏
  • 举报
回复
JToolBar toolBar = new JToolBar();
toolBar.setLayout(new FlowLayout(FlowLayout.LEFT));
// toolBar.setLayout(new FlowLayout(FlowLayout.LEFT, 2, 0));
liaomingxue 2003-10-06
  • 打赏
  • 举报
回复
提前
raysand 2003-10-06
  • 打赏
  • 举报
回复
<![CDATA[
Sorry,Chinese Input failed!!!!!!!!!!!

Set a icon for a JRadioButton component meeting the following:
1: a icon including
2: text excluded
and keeing radiobutton's original round check box to indicate whether checked or not.

High score is available for good answer
]]>
liaomingxue 2003-10-06
  • 打赏
  • 举报
回复
问题是这样的:
radioButton.setText("<html><img src=a image file name>");
可以保留原来的圆形按钮,并将我们的图标放到后面,但是问题是:
我们的这个图标将尽可能地占据剩余空间.如果将这个按钮与其他普通按钮
加到一个工具栏中,我们再最大化窗口,就会发现这个按钮占据了庞大的空间
宽度!!!!!!这是为什么呢?这个按钮变得象glue一样!!!
newman0708 2003-10-05
  • 打赏
  • 举报
回复
对这个网页上有,看过了。
http://javaalmanac.com/egs/javax.swing/checkbox_CustIcon.html
liaomingxue 2003-10-05
  • 打赏
  • 举报
回复
输入法好了,我重新说一下:

按照liad,可以放置两个图标,一个是原来的,用来指示选择状态;
一个是我们配置的,用来显示按钮含义;但是我们定义的图标将占据
很宽的空间,不管怎样设置大小,都无法避免.

按照后面两者的说法,只能放一个图标.
liaomingxue 2003-10-04
  • 打赏
  • 举报
回复
according to liad, the icon we add will hold a very wide space
even if setting a width property for img,td,or tr html tag.
Also, I use img tag directly,but the same result.....

for YuLimin(阿敏当兵) :
the method tells us how to change icon ,not to set a new icon
together with default round icon.
YuLimin 2003-10-04
  • 打赏
  • 举报
回复
import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JApplet;
import javax.swing.JRadioButton;

public class Test extends JApplet
{
public void init()
{
Container contentPane = getContentPane();
Icon icon = new ImageIcon(getImage(getCodeBase(),"bulb.gif"));
JRadioButton[] radioButtons = new JRadioButton[]
{
new JRadioButton(),
new JRadioButton(icon),
new JRadioButton(icon,true),
new JRadioButton("idea!"),
new JRadioButton("idea!",true),
new JRadioButton("idea!",icon),
new JRadioButton("idea!",icon,true)
};
contentPane.setLayout(new FlowLayout());

for(int i = 0;i < radioButtons.length;++i)
{
radioButtons[i].setBorderPainted(true);
contentPane.add(radioButtons[i]);

if(radioButtons[i].getIcon() != null)
{
System.out.println("setting selected icon");
radioButtons[i].setSelectedIcon(new ImageIcon(getImage(getCodeBase(),"bulb_bright.gif")));
}
}
}
}
liad 2003-10-04
  • 打赏
  • 举报
回复
this maybe help
http://javaalmanac.com/egs/javax.swing/pkg.html#JRadioButton
【重要提示】本资源设置为0积分下载,若非0积分请勿轻易下载 亲爱的CSDN用户: 首先感谢你点进这个资源页面。我需要提前说明一个重要情况: 本资源原本已设置为“0积分下载”,即作者希望完全免费共享。但CSDN平台有时会根据文件的下载热度、文件大小、用户权限等因素,自动将部分资源的积分调整为非0数值(如1积分、2积分、5积分等)。这是平台系统的自动行为,而非作者本人的设定。 因此,如果你当前看到该资源的下载所需积分不是0(例如显示为1、2、3……),请谨慎决定是否下载。 如果你按照非0积分支付并下载后发现资源内容不符合预期、链接失效,或者实际上该资源本应是免费的,作者无法为此承担积分损失或退还操作。强烈建议:仅在页面显示为0积分时进行下载。 另外,本资源描述中并未直接提供具体的下载地址或外部链接,因为它本身是一个通过CSDN官方上传通道提交的文件/内容包。如果你看到描述中没有外部网盘地址,这是正常的——资源文件应通过CSDN内置的“下载”按钮获取。若因平台积分显示异常导致你支付了积分,请优先联系CSDN客服咨询积分退还政策,作者没有权限修改平台自动设定的积分值。 感谢你的理解与支持。技术分享本应开放,但受限于平台规则,特此提醒如上。祝学习进步!

62,622

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧