界面按扭大小相同的设定? 有没有办法用一个函数就可以把窗口里的按扭的大小都设为相同?谢谢! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /** * 统一组件大小,以最大的组件大小为标准 * @param components 需要统一大小的组件 */ public void equalizeComponentSizes( JComponent[] components ) { if ( components.length == 0 || components == null ) { return; } // Get the largest width and height int i = 0; Dimension maxPreferred = new Dimension ( 0 , 0 ); JComponent oneComponent = null; Dimension thisPreferred = null; for ( i = 0; i < components.length; ++i ) { oneComponent = ( JComponent ) components[ i ]; thisPreferred = oneComponent.getPreferredSize (); maxPreferred.width = Math.max ( maxPreferred.width , ( int ) thisPreferred.getWidth () ); maxPreferred.height = Math.max ( maxPreferred.height , ( int ) thisPreferred.getHeight () ); } // resize all the conponents with the same size for ( i = 0; i < components.length; ++i ) { oneComponent = ( JComponent ) components[ i ]; oneComponent.setPreferredSize ( ( Dimension ) maxPreferred.clone () ); oneComponent.setMinimumSize ( ( Dimension ) maxPreferred.clone () ); } } 做工具类,CommandHelper 一类的东西,然后通过CommandHelper.create()方法来生成按钮/这样任何地方的按钮都会统一风格 如何在一画板上实现双击添加文本框? 求教材,Java的数据结构与算法之类的 本人有点问题 难道我要抛弃rmi? 问一个简单的问题~~~~ 怎样在eclipse当中使用文件形式替代控制台输入? 请问各位:“小弟现在swing 下插入一个网页,应该如何做? 有办法在选中JTree的一个节点时,禁止selection改变么 有没有大神告诉我一下jsonlib的优缺点 Java小问题求帮助(小白一个) 动态生成复选框 [高分求助] 简单问题
* 统一组件大小,以最大的组件大小为标准
* @param components 需要统一大小的组件
*/
public void equalizeComponentSizes( JComponent[] components )
{
if ( components.length == 0 || components == null )
{
return;
}
// Get the largest width and height
int i = 0;
Dimension maxPreferred = new Dimension ( 0 , 0 );
JComponent oneComponent = null;
Dimension thisPreferred = null;
for ( i = 0; i < components.length; ++i )
{
oneComponent = ( JComponent ) components[ i ];
thisPreferred = oneComponent.getPreferredSize ();
maxPreferred.width =
Math.max ( maxPreferred.width , ( int ) thisPreferred.getWidth () );
maxPreferred.height =
Math.max ( maxPreferred.height ,
( int ) thisPreferred.getHeight () );
} // resize all the conponents with the same size
for ( i = 0; i < components.length; ++i )
{
oneComponent = ( JComponent ) components[ i ];
oneComponent.setPreferredSize ( ( Dimension ) maxPreferred.clone () );
oneComponent.setMinimumSize ( ( Dimension ) maxPreferred.clone () );
}
}
CommandHelper 一类的东西,然后通过CommandHelper.create()方法来生成按钮/
这样任何地方的按钮都会统一风格