简体   繁体   中英

how to remove the checkbox from jcheckbox

I have a jList where I am showing all the elements as jCheckbox. 在此处输入图片说明

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.

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;
        }

}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM