swingx java_有谁在使用SwingX? 急!!!

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

我在运行JXBusyLabel(http://developerlife.com/tutorials/?p=248)这个例子时,jdk中没有LinearGradientPaint这个类,该如何解决?

部分代码:

import org.jdesktop.swingx.*;

import org.jdesktop.swingx.icon.*;

import org.jdesktop.swingx.painter.*;

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

import java.awt.geom.*;

/**

* BusyLabelExample

*

* @author Nazmul Idris

* @version 1.0

* @since Feb 2, 2008, 2:43:30 PM

*/

public class BusyLabelExample {

/** simple main driver for this class */

public static void main(String[] args) {

SwingUtilities.invokeLater(new Runnable() {

public void run() {

new BusyLabelExample();

}

});

}

/** creates a JFrame and calls {@link #doInit} to create a JXPanel and adds the panel to this frame. */

public BusyLabelExample() {

JFrame frame = new JFrame("JXBusyLabel Example");

// add the panel to this frame

frame.add(doInit());

// when you close the frame, the app exits

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

// center the frame and show it

frame.setLocationRelativeTo(null);

frame.pack();

frame.setVisible(true);

}

/** creates a JXLabel and attaches a painter to it. */

private Component doInit() {

JXPanel panel = new JXPanel();

panel.setLayout(new BorderLayout());

// create a busylabel

final JXBusyLabel busylabel1 = createSimpleBusyLabel();

final JXBusyLabel busylabel2 = createComplexBusyLabel();

busylabel1.setEnabled(false);

busylabel2.setEnabled(false);

// create a label

final JXLabel label = createLabel();

// create a button

JButton button = new JButton("start/stop");

button.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

if (!busylabel1.isEnabled()){

busylabel1.setEnabled(true);

busylabel2.setEnabled(true);

}

if (busylabel1.isBusy()) {

label.setText("BusyLabel stopped");

busylabel1.setBusy(false);

busylabel2.setBusy(false);

}

else {

label.setText("BusyLabel started");

busylabel1.setBusy(true);

busylabel2.setBusy(true);

}

}

});

// set the transparency of the JXPanel to 50% transparent

panel.setAlpha(0.7f);

// add the label, busylables, and button to the panel

panel.add(label, BorderLayout.NORTH);

JXPanel busylabels = new JXPanel(new FlowLayout(FlowLayout.CENTER, 40, 5));

busylabels.add(busylabel1);

busylabels.add(busylabel2);

panel.add(busylabels, BorderLayout.CENTER);

panel.add(button, BorderLayout.SOUTH);

panel.setPreferredSize(new Dimension(250, 125));

return panel;

}

public JXBusyLabel createSimpleBusyLabel(){

JXBusyLabel label = new JXBusyLabel();

label.setToolTipText("simple busy label");

return label;

}

public JXBusyLabel createComplexBusyLabel() {

// this will not work in the 0.9.1 release of SwingX (need later builds)

JXBusyLabel label = new JXBusyLabel(new Dimension(38, 38));

BusyPainter painter = new BusyPainter(

new Rectangle2D.Float(0, 0, 8.0f, 8.0f),

new Rectangle2D.Float(5.5f, 5.5f, 27.0f, 27.0f));

painter.setTrailLength(4);

painter.setPoints(8);

painter.setFrame(-1);

painter.setBaseColor(Colors.LightBlue.color());

painter.setHighlightColor(Colors.Orange.color());

label.setPreferredSize(new Dimension(38, 38));

label.setIcon(new EmptyIcon(38, 38));

label.setBusyPainter(painter);

label.setToolTipText("complex busy label");

return label;

}

public JXLabel createLabel() {

JXLabel label = new JXLabel();

label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

label.setFont(new Font("Segoe UI", Font.BOLD, 14));

label.setText("BusyLabel Example...
click start/stop button");

label.setIcon(Images.NetworkDisconnected.getIcon(40, 40));

label.setHorizontalAlignment(JXLabel.LEFT);

label.setBackgroundPainter(getPainter());

return label;

}

/** this painter draws a gradient fill */

public Painter getPainter() {

int width = 100;

int height = 100;

Colors color1 = Colors.White.color(0.5f);

Colors color2 = Colors.Gray.color(0.5f);

LinearGradientPaint gradientPaint =

new LinearGradientPaint(0.0f, 0.0f, width, height,

new float[]{0.0f, 1.0f},

new Colors[]{color1, color2});

MattePainter mattePainter = new MattePainter(gradientPaint);

return mattePainter;

}

}//end class BusyLabelExample

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值