24 Mart 2012 Cumartesi

Icon overlay on taskbar button

Sample code

overlay icon un yanı sıra jump list, progress bar, gibi değişikler yapabilirisiniz taskbar button a.






package com.strixcode.j7goodies.samples;

import com.strixcode.j7goodies.AppUserModelId;
import com.strixcode.j7goodies.TaskbarButton;
import java.awt.EventQueue;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Box;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.UIManager;

/**
* Demonstrates how to use the TaskbarButton class to display an overlay icon.
*/
public class OverlayIconSample extends JFrame implements ActionListener {
TaskbarButton taskbarButton;

public OverlayIconSample() {
super("J7Goodies Demo");

getContentPane().add("Center", new JLabel("Click a button to display an overlay icon"));
Box box = Box.createVerticalBox();


final String[] icons = {"n/a", "images/available.png", "images/away.png",
"images/busy.png", "images/offline.png"
};
final String[] captions = {"No icon", "Available", "Away", "Busy",
"Offline"
};

for (int i = 0; i < icons.length; ++i) {
JButton cb = new JButton(captions[i], loadIcon(icons[i]));
cb.addActionListener(this);
box.add(cb);
}
getContentPane().add("South", box);
}

protected final ImageIcon loadIcon(String path) {
java.net.URL imgURL = this.getClass().getResource(path);
if (imgURL != null)
return new ImageIcon(imgURL);
else
return null;
}

@Override
public void actionPerformed(ActionEvent e) {
JButton button = (JButton) e.getSource();
ImageIcon icon = (ImageIcon) button.getIcon();
if (icon != null)
taskbarButton.setOverlayIcon(icon);
else
taskbarButton.clearOverlayIcon();
}

private void setTaskbarButton(TaskbarButton taskbarButton) {
this.taskbarButton = taskbarButton;
}

public static void main(String[] args) throws Exception {
// AppUserModelID must be set before any GUI is shown
AppUserModelId.setCurrentProcessId("StrixCode.J7Goodies.Trial");

// Access GUI objects on the GUI thread
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception ex) {}

final OverlayIconSample frame = new OverlayIconSample();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.pack();
frame.setVisible(true);

// *After* the frame become visible, create a TaskbarButton
// instance for it.
frame.setTaskbarButton(new TaskbarButton(frame));
}
});
}
}

Hiç yorum yok:

Yorum Gönder