Posted on 2009-04-29 18:08
zht 阅读(560)
评论(0) 编辑 收藏
常用Swing知识点、技巧总结,逐步积累添加中
1、如何给JPanel,JFrame,JDialog设置背景
下载链接
2、如何去掉JTextField中输入文本框时的跟随方框
System.setProperty("java.awt.im.style", "on-the-spot");
3、表格间隔色
JTable table = new JTable() {
public Component prepareRenderer(TableCellRenderer renderer, int row, int column) {
Component prepareRenderer = super.prepareRenderer(renderer, row, column);
if (row % 2 == 0) {
prepareRenderer.setBackground(Color.LIGHT_GRAY);
} else {
prepareRenderer.setBackground(Color.WHITE);
}
return prepareRenderer;
}
};
4、仿MSN弹出面板
下载链接
5、Spinner循环
原理:重载了getNextValue和getPreviousValue两个方法
final SpinnerNumberModel model = new SpinnerNumberModel();
model.setMaximum(new Integer(5));
model.setMinimum(new Integer(0));
final JSpinner spinner = new JSpinner() {
public Object getNextValue() {
if (this.getValue().toString().equals(model.getMaximum().toString())) {
return model.getMinimum();
}
return super.getNextValue();
}
public Object getPreviousValue() {
if (this.getValue().toString().equals(model.getMinimum().toString())) {
return model.getMaximum();
}
return super.getPreviousValue();
}
};
spinner.setModel(model);
6、2D去锯齿
只是因为名称太长...
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING , RenderingHints.VALUE_ANTIALIAS_ON);
7、修改全局文字
public static void setUIFont (javax.swing.plaf.FontUIResource f){
java.util.Enumeration keys = UIManager.getDefaults().keys();
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
Object value = UIManager.get (key);
if (value instanceof javax.swing.plaf.FontUIResource)
UIManager.put (key, f);
}
}
最后修改:10.06.24
zhangtao