Skip to main content

JXTable String/Boolean editor/renderer

3 replies [Last post]
fommil
Offline
Joined: 2006-11-26
Points: 0

Hi all,

I have some cells in a JXTable which are using the standard SwingX renderers/editors for Boolean/String types. I'm seeing two oddities, both can be seen in the video associated to my other post http://www.java.net/forum/topic/javadesktop/java-desktop-technologies/sw...

in the screencast at http://youtu.be/nGaLSyzmdBM

1. I'm seeing a really weird flash of a black background when I click a boolean cell. I believe this is because I have set my table to be non-focusable and this is a quick flash when the button thinks it is getting focus. If I allow my table to obtain focus, then the background of the cell goes completely black if I click it. How can I get rid of this flash?

2. The default Renderer for String entries makes text look like a JLabel, but I want to make it look exactly like the Editor (i.e. like a JTextField). You'll note that this isn't just about having a white background - there are slight subtleties in the spacing of the border/text. How can I do this?

(BTW, I'm aware that I could write my own TableCellEditor, TableCellRenderer pairs, but I would like to know if there is a way to fix the existing implementations first).

Regards, Sam

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
kschaefe
Offline
Joined: 2006-06-08
Points: 0

1. Does that same thing happen with core renderers in a plain JTable?

2. We don't have an implementation of a JTextField renderer. This is not the first request for one. If you file a feature request, we can track that. We'd need to build a TextFieldProvider a la our LabelProvider, possibly with some extra bells to make Icon rendering easier.

Karl

fommil
Offline
Joined: 2006-11-26
Points: 0

kschaefe, this doesn't happen with core renderers because it is specific to JXTable.BooleanRenderer. I seem to have narrowed this behaviour down to when table.setCellSelectionEnabled(false) is called. See below:

import java.awt.BorderLayout;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXTable;

public class Scratch extends JPanel {

    public static void main(String[] args) {
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        Scratch scratch = new Scratch();
        frame.add(scratch, BorderLayout.CENTER);
        frame.setSize(300, 300);
        frame.setVisible(true);
    }

    public Scratch() {
        super();
        JXTable table = new JXTable();
        table.setModel(new BooleanTableModel());
        table.setCellSelectionEnabled(false);
//        table.setFocusable(false);
        add(table);
    }

    class BooleanTableModel extends DefaultTableModel {

        public BooleanTableModel() {
            super(new Object[][]{{"1", Boolean.TRUE}, {"2", Boolean.TRUE}, {"3", Boolean.FALSE},
                        {"4", Boolean.TRUE}, {"5", Boolean.FALSE}}, new String[]{"Number", "Boolean"});
        }

        @Override
        public Class<?> getColumnClass(int columnIndex) {
            switch (columnIndex) {
                case 0:
                    return String.class;

                case 1:
                    return Boolean.class;

                default:
                    return Object.class;
            }
        }
    }
}
fommil
Offline
Joined: 2006-11-26
Points: 0

1. I'll look into setting up a standalone test case for you.

2. You're going to have to point me to the issue tracker for RFEs because all the changes on java.net have me completely lost.

BTW, have you spotted the typo "JXTextField.setPromptBack[_]round(Color)" ;-) I'm wondering if this has anything to do with another white/grey problem I'm experiencing...