如何表示双值作为一个二维矩阵在Java中圈
-
26-09-2019 - |
题
所以想要写的矩阵探险这使我重新排序行和矩阵的列。 对于这个porpouse我用JTable类。现在,我的问题是,这是很困难的看着双重价值重新排列矩阵,所以我想打印的基体不与双重价值,但有圈中圆的半径代表值。所以,我可以告诉大值和小值更快的区别。
任何人有任何想法我怎么可以把这个双重价值与JTable中或任何与此有关的表类实心圆?
解决方案
这里的一个定制渲染器的一例一>实现了Icon
界面做图。这种方法可以在文本和图标的相对位置更容易控制。请注意,基于在所述间隔[0, 1)
归一化值的假设渲染器鳞片;你可能想查询的最小值和最大值的数据模型来代替。
class DecRenderer extends DefaultTableCellRenderer implements Icon {
private static final int SIZE = 32;
private static final int HALF = SIZE / 2;
DecimalFormat df;
public DecRenderer(DecimalFormat df) {
this.df = df;
this.setIcon(this);
this.setHorizontalAlignment(JLabel.RIGHT);
this.setBackground(Color.lightGray);
}
@Override
protected void setValue(Object value) {
setText((value == null) ? "" : df.format(value));
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(
RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setColor(Color.blue);
double v = Double.valueOf(this.getText());
int d = (int)(v * SIZE);
int r = d / 2;
g2d.fillOval(x + HALF - r, y + HALF - r, d, d);
}
@Override
public int getIconWidth() {
return SIZE;
}
@Override
public int getIconHeight() {
return SIZE;
}
}
其他提示
您必须编写自定义的单元格渲染
该组件将被用作橡皮图章;该paint
方法被称为用于每个小区。
绘制在油漆方法圆;
g.fillOval(x - radius / 2, y - radius / 2, radius, radius);
将绘制radius
的圆与(x,y)
中心点。
不隶属于 StackOverflow