今天突然想到这样一个问题:用SWING来实现类似EXCEL中条件格式效果的实现请见下图:
点击“添加”添加一个条件,点击“删除”把选中的一个条件删除。再加一个按钮,点击“隐藏”把选中的条件隐藏。
个人感觉实现有一定的难度,希望大家来发表一下你们的建议。
点击“添加”添加一个条件,点击“删除”把选中的一个条件删除。再加一个按钮,点击“隐藏”把选中的条件隐藏。
个人感觉实现有一定的难度,希望大家来发表一下你们的建议。
解决方案 »
- import sun.management.ManagementFactory 出错为什么怎么改
- 在main方法中System.exit(0)与return 有什么区别???
- 高手请进
- 请问如何将一个字符串中的正斜杠替换为反斜杠啊?
- 编写一个类,名为Singleton.java实现功能如下: Singleton类只存在一个实例(只能被实例化一次)。
- 请问那里出错,急!!!
- SQL语句不能正确执行,高分求助
- 高手们帮帮忙(关于LDAP)
- 谁用过installanywhere做JAVA的安装程序啊?为什么会出现中文问题阿
- p2p寻址的问题。
- 如何将JTable生成的表格倒入Excel
- 如何运行EXCEL文件
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;import javax.swing.*;
public class T {
public static void main(String[] args) {
final JPanel cp = new JPanel(new GridLayout(0, 1, 0, 5));
JPanel bp = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5));
JButton addBtn = new JButton("Add");
JButton removeBtn = new JButton("Remove");
addBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
cp.add(new ConditionPanel(cp.getComponentCount() + 1));
SwingUtilities.getWindowAncestor(cp).pack();
}
});
removeBtn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (cp.getComponentCount() > 0) {
cp.remove(cp.getComponentCount()-1);
SwingUtilities.getWindowAncestor(cp).pack();
}
}
});
bp.add(addBtn);
bp.add(removeBtn);
JFrame f = new JFrame();
f.getContentPane().add(cp, BorderLayout.CENTER);
f.getContentPane().add(bp, BorderLayout.SOUTH);
f.pack();
f.setLocationRelativeTo(null);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.setVisible(true);
}
}class ConditionPanel extends JPanel
{
public ConditionPanel(int id) {
super(new BorderLayout());
setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(), "条件" + id));
JLabel l = new JLabel("test");
l.setBorder(BorderFactory.createEmptyBorder(20, 200, 20, 200));
add(l, BorderLayout.CENTER);
}
}
佩服。
http://blog.csdn.net/bovy/archive/2007/04/06/1554644.aspx