how to represent double values as circles in a 2d matrix in java

how to represent double values as circles in a 2d matrix in java  using -'java,swing,information-visualization'

so I want to write a matrix explorer which enables me to reorder rows and columns of a matrix.
For this porpouse I used the Jtable class. Now the problem that I have is that it is very difficult to reorder a matrix by looking at double values, so I would like to print the matrix not with the double values but with circles in which the radius of the circle represents the value. So that I can tell the difference between big values and small values quicker.

Anybody has any idea how I can turn this double values into filled circles with JTable or any table class for that matter?

asked Sep 22, 2015 by vibhorsingh
0 votes

2 Answers

0 votes

Here's an example of a custom renderer that implements the Icon interface to do the drawing. This approach permits easier control over the relative positioning of the text and icon. Note that the renderer scales based on the assumption of normalized values in the interval [0, 1); you may want to query your data model for the minimum and maximum values instead.

alt text

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;

    protected void setValue(Object value) {
        setText((value == null) ? "" : df.format(value));

    public void paintIcon(Component c, Graphics g, int x, int y) {
        Graphics2D g2d = (Graphics2D) g;
        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);

    public int getIconWidth() {
        return SIZE;

    public int getIconHeight() {
        return SIZE;
answered Sep 22, 2015 by abhi
0 votes

You will have to write your custom Cell Renderer.

The component will be used as a rubber stamp; the paint method is called for each cell.

Draw the circle in the paint method;

g.fillOval(x - radius / 2, y - radius / 2, radius, radius);

Will draw a circle of radius with center point at (x,y).

answered Sep 22, 2015 by manju bhargava