日期:2014-05-20 浏览次数:20987 次
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.Popup;
import javax.swing.PopupFactory;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class MutiProgressBar extends JFrame {
private DefaultTableModel dtm;
private JTable tbl;
private JLabel statusLab;
private JScrollPane jsp;
private ProgressPan proPan;
private Popup popup;
private PopupFactory popupFatory = PopupFactory.getSharedInstance();
public MutiProgressBar() {
initComponents();
addListeners();
}
private void initComponents() {
JPanel pan = new JPanel();
pan.setOpaque(true);
setContentPane(pan);
jsp = new JScrollPane();
pan.setLayout(new BorderLayout());
pan.add(jsp, BorderLayout.CENTER);
JPanel statusPan = new JPanel();
statusPan.setPreferredSize(new Dimension(500, 20));
statusPan.setLayout(new BorderLayout());
statusPan.add(new JPanel(), BorderLayout.CENTER);
statusLab = new JLabel();
statusLab.setEnabled(false);
statusLab.setPreferredSize(new Dimension(200, 20));
statusLab.setBorder(BorderFactory.createEtchedBorder(Color.lightGray, Color.yellow));
statusLab.setText("0 Jobs are running...");
statusPan.add(statusLab, BorderLayout.EAST);
pan.add(statusPan, BorderLayout.SOUTH);
String[][] data = {{"R1C1", "R1C2"}, {"R2C1", "R2C2"}, {"R3C1", "R3C2"}};
String[] header = {"Column1", "Column2"};
dtm = new DefaultTableModel(data, header) {
@Override
public boolean isCellEditable(int row, int column) {
return false;
}
};
tbl = new JTable(dtm);
jsp.setViewportView(tbl);
proPan = new ProgressPan();
}
private void addListeners() {
statusLab.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent evt) {
if (popup == null) {
popup = popupFatory.getPopup(MutiProgressBar.this, proPan, statusLab.getLocationOnScreen().x, statusLab.getLocationOnScreen().y - proPan.size.height);
popup.show();
} else {
popup.hide();
popup = null;
}
}
});
tbl.addMouseListener(new MouseAdapter() {
@Override
/*
* 鼠标事件触发添加任务
*/
public void mouseClicked(MouseEvent evt) {
if (tbl.getSelectedRow() != -1) {
Task task = new Task(tbl.getSelectedRow() + tbl.getSelectedColumn(), evt.getPoint().toString().substring(21));