/*
* (swing1.1beta3)
*/
package jp.gr.java_conf.tame.swing.table;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
/**
* @version 1.0 11/22/98
*/
public class AttributiveCellRenderer extends JLabel
implements TableCellRenderer {
protected static Border noFocusBorder;
public AttributiveCellRenderer() {
noFocusBorder = new EmptyBorder(1, 2, 1, 2);
setOpaque(true);
setBorder(noFocusBorder);
} public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color foreground = null;
Color background = null;
Font font = null;
TableModel model = table.getModel();
if (model instanceof AttributiveCellTableModel) {
CellAttribute cellAtt = ((AttributiveCellTableModel)model).getCellAttribute();
if (cellAtt instanceof ColoredCell) {
foreground = ((ColoredCell)cellAtt).getForeground(row,column);
background = ((ColoredCell)cellAtt).getBackground(row,column);
}
if (cellAtt instanceof CellFont) {
font = ((CellFont)cellAtt).getFont(row,column);
}
}
if (isSelected) {
setForeground((foreground != null) ? foreground
: table.getSelectionForeground());
setBackground(table.getSelectionBackground());
} else {
setForeground((foreground != null) ? foreground
: table.getForeground());
setBackground((background != null) ? background
: table.getBackground());
}
setFont((font != null) ? font : table.getFont());
if (hasFocus) {
setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
if (table.isCellEditable(row, column)) {
setForeground((foreground != null) ? foreground
: UIManager.getColor("Table.focusCellForeground") );
setBackground( UIManager.getColor("Table.focusCellBackground") );
}
} else {
setBorder(noFocusBorder);
}
setValue(value);
return this;
}
protected void setValue(Object value) {
setText((value == null) ? "" : value.toString());
}
}
* (swing1.1beta3)
*/
package jp.gr.java_conf.tame.swing.table;
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.border.*;
/**
* @version 1.0 11/22/98
*/
public class AttributiveCellRenderer extends JLabel
implements TableCellRenderer {
protected static Border noFocusBorder;
public AttributiveCellRenderer() {
noFocusBorder = new EmptyBorder(1, 2, 1, 2);
setOpaque(true);
setBorder(noFocusBorder);
} public Component getTableCellRendererComponent(JTable table, Object value,
boolean isSelected, boolean hasFocus, int row, int column) {
Color foreground = null;
Color background = null;
Font font = null;
TableModel model = table.getModel();
if (model instanceof AttributiveCellTableModel) {
CellAttribute cellAtt = ((AttributiveCellTableModel)model).getCellAttribute();
if (cellAtt instanceof ColoredCell) {
foreground = ((ColoredCell)cellAtt).getForeground(row,column);
background = ((ColoredCell)cellAtt).getBackground(row,column);
}
if (cellAtt instanceof CellFont) {
font = ((CellFont)cellAtt).getFont(row,column);
}
}
if (isSelected) {
setForeground((foreground != null) ? foreground
: table.getSelectionForeground());
setBackground(table.getSelectionBackground());
} else {
setForeground((foreground != null) ? foreground
: table.getForeground());
setBackground((background != null) ? background
: table.getBackground());
}
setFont((font != null) ? font : table.getFont());
if (hasFocus) {
setBorder( UIManager.getBorder("Table.focusCellHighlightBorder") );
if (table.isCellEditable(row, column)) {
setForeground((foreground != null) ? foreground
: UIManager.getColor("Table.focusCellForeground") );
setBackground( UIManager.getColor("Table.focusCellBackground") );
}
} else {
setBorder(noFocusBorder);
}
setValue(value);
return this;
}
protected void setValue(Object value) {
setText((value == null) ? "" : value.toString());
}
}
解决方案 »
- 一道面试题(请大家帮忙看一下这道题目如何作答)
- 短信猫Linux平台JAVA二次开发包RXTX发送短信出现No response from devic异常
- 在ibatis的xml文件中如何处理表达式中的中文字符?
- 如何拿到调用某方法的对象的引用
- 请教,如何让我自己的servlet能显示控制台窗口打印当前信息。
- 大家共享几道面试题,一起解决下![力顶推荐,顶着有分]
- 关于重载时的可变参数列表问题
- DataOutputStream与DataInputStream主要在哪些情况下用到?用什么很实际的例子么??
- 为什么我的程序一运行就停住了?
- 关于JEitorPane这个类它都能完成什么功能啊?
- 有关Class.forName()的问题?
- 发几篇swing中关于JTable中的运用-3
* (swing1.1beta3)
*/
package jp.gr.java_conf.tame.swing.colorchooser;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
* @version 1.0 11/22/98
*/
class TextPreviewLabel extends JLabel {
private String sampleText = " Sample Text Sample Text ";
boolean isForgroundSelection;
public TextPreviewLabel() {
this(Color.black, Color.white, true);
}
public TextPreviewLabel(Color fore, Color back, boolean isForgroundSelection) {
setOpaque(true);
setForeground(fore);
setBackground(back);
this.isForgroundSelection = isForgroundSelection;
setText(sampleText);
}
public void setForeground(Color col) {
if (isForgroundSelection) {
super.setForeground(col);
} else {
super.setBackground(col);
}
}
}
class ColorChooserDialog extends JDialog {
private Color initialColor;
private Color retColor;
private JColorChooser chooserPane; public ColorChooserDialog(Component c, String title,
final JColorChooser chooserPane) {
super(JOptionPane.getFrameForComponent(c), title, true);
setResizable(false); this.chooserPane = chooserPane; String okString = UIManager.getString("ColorChooser.okText");
String cancelString = UIManager.getString("ColorChooser.cancelText");
String resetString = UIManager.getString("ColorChooser.resetText"); Container contentPane = getContentPane();
contentPane.setLayout(new BorderLayout());
contentPane.add(chooserPane, BorderLayout.CENTER); JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.CENTER));
JButton okButton = new JButton(okString);
getRootPane().setDefaultButton(okButton);
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
retColor = chooserPane.getColor();
setVisible(false);
}
});
buttonPane.add(okButton); JButton cancelButton = new JButton(cancelString);
cancelButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
retColor = null;
setVisible(false);
}
});
buttonPane.add(cancelButton); JButton resetButton = new JButton(resetString);
resetButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
chooserPane.setColor(initialColor);
}
});
buttonPane.add(resetButton);
contentPane.add(buttonPane, BorderLayout.SOUTH); pack();
setLocationRelativeTo(c);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
setVisible(false);
}
});
}
public Color getColor() {
return retColor;
}}
public class TextColorChooser extends JColorChooser {
public TextColorChooser(Color target, Color reference, boolean isForgroundSelection) {
super(target);
if (isForgroundSelection) {
setPreviewPanel(new TextPreviewLabel(target, reference,isForgroundSelection));
} else {
setPreviewPanel(new TextPreviewLabel(reference,target, isForgroundSelection));
}
updateUI();
}
public Color showDialog(Component component, String title) {
ColorChooserDialog dialog = new ColorChooserDialog(component, title, this);
dialog.show();
Color col = dialog.getColor();
dialog.dispose();
return col;
}
}
DefaultCellAttribute.java
CellAttribute.java
ColoredCell.java
CellFont.java
CellSpan.java
MultiSpanCellTable.java
MultiSpanCellTableUI.java
AttributiveCellRenderer.java
TextColorChooser.java
老兄,文章开头已经注明了啊!
何况那个网站现在已经上不了了.........