user1631306
user1631306

Reputation: 4470

how to remove the checkbox from jcheckbox

I have a jList where I am showing all the elements as jCheckbox. enter image description here

Now, I want the first item "new tag" to act like a button. Means, when user click on it, it opens a new dialog box and does something. That part is working, but I want to get rid of the checkbox, so it doesnt get confusing to user. How can I hide the checkbox square and just keep the text.

Upvotes: 0

Views: 720

Answers (1)

user1631306
user1631306

Reputation: 4470

I imlemented listcellrender with following code

public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean hasFocus)
    {
        String str = (value == null) ? "" : value.toString();


        if ("New Tag...".equals(str))
        {
            JButton button = new JButton(str);
            button.setBorderPainted(false);
            button.setContentAreaFilled(false);
            button.setFocusPainted(false);
            button.setOpaque(false);
            button.setMargin(new Insets(0, 24, 0, 0));
            button.setHorizontalAlignment(SwingConstants.LEFT);
            return button;
        }

}

Upvotes: 1

Related Questions