Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 237143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:24:07+00:00 2026-05-11T20:24:07+00:00

Hi I have a class called ColorChooser (in the net.java.dev.colorchooser.ColorChooser package) This is a

  • 0

Hi I have a class called ColorChooser (in the net.java.dev.colorchooser.ColorChooser package)

This is a custom component used to select colors. What I want is to display a JTable with ColorChoosers in the second column. So I created my own TableCellRenderer and it works:

@SuppressWarnings("serial")
class ColorChooserTableRenderer extends DefaultTableCellRenderer {

    public static List<ColorChooser> colors;

    public ColorChooserTableRenderer(int rows) {
        colors = new ArrayList<ColorChooser>(rows);
        for (int i = 0; i<rows ; i ++) {
            colors.add(new ColorChooser());
        }
    }

    @Override
    public Component getTableCellRendererComponent(JTable table, Object value,
            boolean isSelected, boolean hasFocus, int row, int column) {
        return colors.get(row);
    }

}

I register this in my table :

JTable t = new JTable(5,3);
t.getColumn(t.getColumnName(1)).setCellRenderer(new ColorChooserTableRenderer(5));

The display is good. It even displays the tool tip of the ColorChoosers when i hover my mouse over one of them. The problem is that the ColorChoosers do not receive MouseEvents.

Normally when you press and hold the mouse on a ColorChooser, you get a pop up window that you can use to select a color. When in the JTable the ColorChooser component does not receive the mouse event.

Any solutions?

Edit: The question can be easily modified to this:

Can you please give me a small example of a table containing JButtons in the second column that actually work? You know, buttons that can be pressed?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T20:24:07+00:00Added an answer on May 11, 2026 at 8:24 pm

    A renderer only paints the component on the screen and does not allow for interaction. What you need is to also implement a TableCellEditor. It is recommend that you inherit the AbstractCellEditor and you’ll save some work. Check out the java tutorial for tables.

    Example:

    public class MyTableCellRenderer implements TableCellRenderer
    {
        private JButton button = new JButton("Press Me");
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            return button;
        }
    }
    
    public class MyTableCellEditor extends AbstractCellEditor implements TableCellEditor
    {
        private JButton button;
    
        public MyTableCellEditor()
        {
            button = new JButton("Press Me");
            button.addActionListener(new ActionListener(){
    
                public void actionPerformed(ActionEvent e) {
                    System.out.println("buttonPressed");
                }
            });
        }
        public Object getCellEditorValue() {
            return null;
        }
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            return button;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class called XMLtoXML.java and this is one of it's methods... import
I have a class called CoverFlowClass. I used to do this to create a
i have this class called MemoryManager, it is supposed to implement a simple smart
I have this class called SiteAsyncDownload.cs Here's the code: public class SiteAsyncDownloader { WebClient
I have a class called MyClass This class inherits IEquatable and implements equals the
I have a class called MainGame, which is defined like this in my .h:
I have a Ruby class called LibraryItem . I want to associate with every
I have a class of buttons called Keys.java which returns a panel of buttons
I have a class called RemoteError with a self.fatal method on it. This methods
i have class call example1 this class defines a background, and i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.