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
...全文
100 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
内容概要:本文围绕基于交替方向乘子法(ADMM)的多主体综合能源系统分布式协同优化展开研究,提出了一种兼顾系统整体性能与各主体隐私保护的分布式优化框架,并提供了完整的Matlab代码实现。研究详细构建了包含电、热、气等多种能源形式耦合的多主体综合能源系统模型,设计了基于ADMM算法的分布式求解机制,实现了在去中心化架构下的协同优化调度。文中深入分析了算法的迭代流程、收敛条件及关键参数(如惩罚因子)对优化性能的影响,通过仿真实验验证了该方法在提升能源利用效率、促进多能协同、降低运行成本方面的有效性,适用于园区微网、能源互联网等复杂场景下的分布式决策需求。; 适合人群:具备一定优化理论基础和Matlab编程能力的研究生、科研人员及从事综合能源系统、智能电网、分布式能源管理等相关领域的工程技术人员。; 使用场景及目标:①实现多主体综合能源系统中电、热、气等多能流的协同调度与优化运行;②解决传统集中式优化带来的数据隐私泄露和计算负担过重问题,支持去中心化的分布式决策模式;③为能源互联网、智慧园区、微电网等实际应用场景提供可复现、易拓展的算法原型与技术参考。; 阅读建议:建议读者结合所提供的Matlab代码进行动手实践,重点理解ADMM算法中增广拉格朗日函数的构造、变量更新规则及收敛判据的实现过程,关注惩罚参数设置对算法收敛速度与稳定性的影响,可进一步尝试将其拓展应用于其他分布式优化问题或与其他智能算法进行性能对比研究。

62,622

社区成员

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

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