成人午夜视频全免费观看高清-秋霞福利视频一区二区三区-国产精品久久久久电影小说-亚洲不卡区三一区三区一区

Java實(shí)現(xiàn)Swing組件定制Button示例-創(chuàng)新互聯(lián)

本文實(shí)例講述了Java實(shí)現(xiàn)Swing組件定制Button。分享給大家供大家參考,具體如下:

創(chuàng)新互聯(lián)建站是一家專(zhuān)注于做網(wǎng)站、網(wǎng)站建設(shè)與策劃設(shè)計(jì),丹江口網(wǎng)站建設(shè)哪家好?創(chuàng)新互聯(lián)建站做網(wǎng)站,專(zhuān)注于網(wǎng)站建設(shè)10多年,網(wǎng)設(shè)計(jì)領(lǐng)域的專(zhuān)業(yè)建站公司;建站業(yè)務(wù)涵蓋:丹江口等地區(qū)。丹江口做網(wǎng)站價(jià)格咨詢(xún):18980820575

先來(lái)看看運(yùn)行效果圖:

Java實(shí)現(xiàn)Swing組件定制Button示例

具體代碼如下:

package themedemo;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.RenderingHints;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.Painter;
import javax.swing.SwingUtilities;
import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
public class ButtonSkinDemo {
 public static void main(String[] args) {
  SwingUtilities.invokeLater(new Runnable() {
   public void run() {
    for (UIManager.LookAndFeelInfo laf : UIManager
      .getInstalledLookAndFeels()) {
     if ("Nimbus".equals(laf.getName())) {
      try {
       UIManager.setLookAndFeel(laf.getClassName());
      } catch (Exception e) {
       e.printStackTrace();
      }
     }
    }
    for (Map.Entry<Object, Object> entry : UIManager
      .getLookAndFeelDefaults().entrySet()) {
     if ((entry.getKey().toString()).startsWith("Button")) {
      System.out.println(entry.getKey() + " = "
        + entry.getValue());
     }
    }
    JFrame frame = new JFrame("www.jb51.net - Button Skining Demo");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    frame.getContentPane().setLayout(new BorderLayout());
    JPanel panel = new JPanel(new GridLayout(0, 1, 20, 20));
    panel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
    panel.setBackground(Color.darkGray);
    UIDefaults buttonDefaults = new UIDefaults();
    buttonDefaults.put("Button.backgroundPainter",
      new Painter<JComponent>() {
       public void paint(Graphics2D g, JComponent c,
         int w, int h) {
        g.setRenderingHint(
          RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);
        g.setStroke(new BasicStroke(2f));
        g.setColor(Color.WHITE);
        g.fillRoundRect(0, 0, w - 2, h - 2, 8, 8);
        g.setColor(Color.LIGHT_GRAY);
        g.drawRoundRect(0, 0, w - 2, h - 2, 8, 8);
       }
      });
    buttonDefaults.put("Button[Pressed].backgroundPainter",
      new Painter<JComponent>() {
       public void paint(Graphics2D g, JComponent c,
         int w, int h) {
        g.setRenderingHint(
          RenderingHints.KEY_ANTIALIASING,
          RenderingHints.VALUE_ANTIALIAS_ON);
        g.setStroke(new BasicStroke(2f));
        g.setColor(Color.LIGHT_GRAY);
        g.fillRoundRect(0, 0, w - 2, h - 2, 8, 8);
       }
      });
    JButton button = new JButton("myButton");
    panel.add(button);
    button.putClientProperty("Nimbus.Overrides", buttonDefaults);
    button.putClientProperty("Nimbus.Overrides.InheritDefaults",
      false);
    // Add a normal themed slider for comparison
    JButton normalButton = new JButton("normalButton");
    panel.add(normalButton);
    frame.getContentPane().add(panel, BorderLayout.CENTER);
    frame.pack();
    frame.setLocationRelativeTo(null);
    frame.setVisible(true);
   }
  });
 }
}

當(dāng)前文章:Java實(shí)現(xiàn)Swing組件定制Button示例-創(chuàng)新互聯(lián)
標(biāo)題網(wǎng)址:http://jinyejixie.com/article20/jjcco.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站建設(shè)、網(wǎng)站制作網(wǎng)站導(dǎo)航、小程序開(kāi)發(fā)、電子商務(wù)、靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)

商城網(wǎng)站建設(shè)
北流市| 五原县| 巴林左旗| 五河县| 汨罗市| 巩义市| 阿城市| 浮山县| 山丹县| 肇庆市| 牡丹江市| 新泰市| 丰宁| 易门县| 海伦市| 成都市| 太谷县| 资阳市| 离岛区| 武义县| 新田县| 沙湾县| 廊坊市| 琼中| 巴马| 海淀区| 鄂托克旗| 鄂托克前旗| 蒲江县| 大竹县| 伊吾县| 深州市| 金阳县| 安化县| 上饶县| 榆树市| 南涧| 新兴县| 曲阳县| 若尔盖县| 连平县|