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

  • Home
  • SEARCH
  • 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 941499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:07:44+00:00 2026-05-15T22:07:44+00:00

How to make the jList selectable and jScrollPane scrollable inside a jTable. This is

  • 0

How to make the jList selectable and jScrollPane scrollable inside a jTable.

This is my table code :

private JTable getCalendarTable() {
    if (calendarTable == null) {
        calendarTable = new JTable() {
            public boolean isCellEditable(int nRow, int nCol) {
                if (nRow % 2 != 0) {
                    return true;
                } else
                    return false;
            }
        };
        DefaultTableModel mtblCalendar = (DefaultTableModel) calendarTable
                .getModel();
        String[] headers = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri",
                "Sat" };
        for (int i = 0; i < 7; i++) {
            mtblCalendar.addColumn(headers[i]);
        }
        calendarTable.setCellSelectionEnabled(true);
        calendarTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        calendarTable.setRowHeight(60);
        mtblCalendar.setColumnCount(7);
        mtblCalendar.setRowCount(12);
        GregorianCalendar cal = new GregorianCalendar();
        realDay = cal.get(GregorianCalendar.DAY_OF_MONTH); // Get day
        realMonth = cal.get(GregorianCalendar.MONTH); // Get month
        realYear = cal.get(GregorianCalendar.YEAR); // Get year
        currentMonth = realMonth; // Match month and year
        currentYear = realYear;
        refreshCalendar(currentMonth, currentYear);
    }

    return calendarTable;
}


class tblCalendarRenderer extends JTextArea implements TableCellRenderer {
    public Component getTableCellRendererComponent(JTable table,
            Object value, boolean selected, boolean focused, int row,
            int column) {
        this.setText(value == null ? "" : value.toString());
        this.setLineWrap(true);
        this.setWrapStyleWord(true);

        if (column == 0 || column == 6) { // Week-end
            setBackground(new Color(255, 220, 220));
        } else { // Week
            setBackground(new Color(255, 255, 255));
        }
        if (row % 2 == 0) {
            if (value != null) {
                if (Integer.parseInt(value.toString()) == realDay
                        && currentMonth == realMonth
                        && currentYear == realYear) { // Today
                    setBackground(new Color(220, 220, 255));
                }
            }
        } else {
            if (value != null) {
                                    // Here is just an test data I want to make sure the jList is working. When 
                                    // the date has event, show jList 
                JList list = new JList(new Object[] { "werwre", "fsdfsd",
                        "details", "computer", "folder", "computer" });
                list.setVisibleRowCount(4);
                JScrollPane pane = new JScrollPane(list);
                list.setCellRenderer(new Incorenderer());
                return pane;
            }
        }
        return this;
    }
}

}

The JList and JScrollPanel appeared when the date has event. But the jList was unselectable and the scrollpanel was unscrollable.

  • 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-15T22:07:45+00:00Added an answer on May 15, 2026 at 10:07 pm

    You need to use your code that draws a JList in a TableCellRenderer implementation and use it as an editor, i.e.:

    class CalendarCellEditor extends AbstractCellEditor implements TableCellEditor {
        public Component getTableCellEditorComponent(JTable table,
                Object value, boolean isSelected, int row, int column) {
    
            if (value != null) {
                // Here is just an test data I want to make sure the jList is
                // working. When
                // the date has event, show jList
                JList list = new JList(new Object[] { "werwre", "fsdfsd",
                        "details", "computer", "folder", "computer" });
                list.setVisibleRowCount(4);
                JScrollPane pane = new JScrollPane(list);
                list.setCellRenderer(new Incorenderer());
                return pane;
            } else {
                // TODO return whatever you need
                return null;
            }
        }
    
        public Object getCellEditorValue() {
            // TODO return whatever you need
            return 1;
        }
    
    }
    

    And add this editor to your table by overriding the following method in you anonymous inner JTable class:

    public TableCellEditor getCellEditor(int row, int column) {
         return new CalendarCellEditor();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 492k
  • Answers 492k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here is a snippet from the MessageComposeResult struct's discussion in… May 16, 2026 at 10:22 am
  • Editorial Team
    Editorial Team added an answer I figured out how to do it using gsl, at… May 16, 2026 at 10:22 am
  • Editorial Team
    Editorial Team added an answer Looks like a problem in your SMS library. In particular,… May 16, 2026 at 10:22 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I'm trying to change a JList inside a JScrollPane dynamically, using myList.setListData(someArray); After this
I want to make my JList editable, what should I do?
how can i make a swing JList to have its items selected with any
Any time I make a custom cell renderer for a JList, any elements I
How can I make a list model from a JList in order to be
I have a JList inside a Scrollpane. If you click on the list and
I make some changes in local files, how can I deploy the new version?
I need to make a copy of a row in a table and also
So Im trying to make an object dynamically, please see below code from my
I know this is kind of a beginners question but my books aren't explaining

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.