首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

批改JButton的L&F,Java也可以

2012-12-19 
修改JButton的L&F,Java也可以buttonA.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY,Subs

修改JButton的L&F,Java也可以

buttonA.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, SubstanceConstants.Side.LEFT); //这是button里里面的方法,参数很好理解,第一个是隐藏button的边,第二个是隐藏哪一个边。 //如果同时隐藏的边数超过1的话,就需要用到容器EnumSet。 // 自然就是把第二个参数改为EnumSet类型。 //EnumSet自然就是存放所有的要隐藏或者是修改的边。EnumSet<Side> leftTopSides = EnumSet.of(SubstanceConstants.Side.LEFT, SubstanceConstants.Side.TOP); buttonC.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, leftTopSides); buttonC.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, leftTopSides);

buttonA.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, SubstanceConstants.Side.LEFT);//这段代码是将边修改为直线型的

package button;import java.awt.FlowLayout;import java.util.EnumSet;import javax.swing.JButton;import javax.swing.JFrame;import javax.swing.SwingUtilities;import javax.swing.UIManager;import org.jvnet.substance.SubstanceLookAndFeel;import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;import org.jvnet.substance.utils.SubstanceConstants;import org.jvnet.substance.utils.SubstanceConstants.Side;public class Buttontest extends JFrame { /** * Creates the main frame for <code>this</code> sample. */ public Buttontest() { super("Buttons with open sides"); this.setLayout(new FlowLayout()); JButton buttonA = new JButton("left only"); // mark button to have open and straight left side // using side constant buttonA.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, SubstanceConstants.Side.LEFT); //这是button里里面的方法,参数很好理解,第一个是隐藏button的边,第二个是隐藏哪一个边。 //如果同时隐藏的边数超过1的话,就需要用到容器EnumSet。 // 自然就是把第二个参数改为EnumSet类型。 //EnumSet自然就是存放所有的要隐藏或者是修改的边。 buttonA.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, SubstanceConstants.Side.LEFT); JButton buttonB = new JButton("right only"); // mark button to have open and straight right side using side constant buttonB.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, SubstanceConstants.Side.RIGHT); buttonB.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, SubstanceConstants.Side.RIGHT); JButton buttonC = new JButton("left+top"); // mark button to have open and straight left and top sides // using set of side constants EnumSet<Side> leftTopSides = EnumSet.of(SubstanceConstants.Side.LEFT, SubstanceConstants.Side.TOP); buttonC.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, leftTopSides); buttonC.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, leftTopSides); JButton buttonD = new JButton("right+bottom"); // mark button to have open and straight right and bottom sides // using set of side constants EnumSet<Side> rightBottomSides = EnumSet.of(SubstanceConstants.Side.RIGHT, SubstanceConstants.Side.BOTTOM); buttonD.putClientProperty(SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY, rightBottomSides); buttonD.putClientProperty( SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY, rightBottomSides); this.add(buttonA); this.add(buttonB); this.add(buttonC); this.add(buttonD); this.setSize(400, 200); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } /** * The main method for <code>this</code> sample. The arguments are ignored. * * @param args * Ignored. * @throws Exception * If some exception occured. Note that there is no special treatment * of exception conditions in <code>this</code> sample code. */ public static void main(String[] args) throws Exception { UIManager.setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel()); JFrame.setDefaultLookAndFeelDecorated(true); SwingUtilities.invokeLater(new Runnable() { public void run() { new Buttontest().setVisible(true); } }); }}

?

最后一点实现这个必须引入第三方包,不过这个包网上下载的很多是错的。很让人恼火,不过幸好找到一个差不多的,让我我就放到附件里面,有需要的话,各位可以下载。

<!--EndFragment-->

热点排行