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));
详细解决方案
swing 如何让Popup和JPanel自动调整大小和位置
热度:10770 发布时间:2013-02-25 00:00:00.0
相关解决方案
- swing JPanel 暗藏
- swing JPanel 隐藏,该如何处理
- Swing 中用Spring如何注入不了 对象为null值
- SWING,该怎么处理
- java swing or applet?解决方法
- swing 界面如何返回上一页
- open swing 如何使用
- swing:为什么一个类里调用另一个类的panel不显示解决办法
- JAVA SWING 中障蔽系统热键
- awt swing 命令行中文乱码解决方案
- swing 相关
- [Java][Swing]可以开发多点触摸桌面程序吗?win7系统上
- java swing,设置窗体无边框(title),如何通过鼠标拖动调整大小
- swing gridLayout,该怎么处理
- JPanel 格局管理器 加空白边缘用哪个方法
- Swing: removeAll()不起作用!求大牛抢救~
- swing gridLayout解决方法
- [swing] JTable如何给选中行添加监听器
- swing 如何让Popup和JPanel自动调整大小和位置
- spark Jpanel 组件格局
- swing canvas下怎么显示图片
- Swing GridBagLayout 布局的有关问题
- java界面(awt,swing,事件机制),该如何处理
- J2SE JPanel 空布局嵌套有关问题
- swing 定制鼠标光标有关问题
- java swing 图片输出解决方法
- java swing 组件大小偶尔不能调整,该怎么处理
- javax.swing.UIManager 干吗用
- Swing 怎么弹出模式窗体,同时窗体下有最大化、最小化和关闭按钮
- java swing 如何实现窗口振动效果