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 8905273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T02:21:20+00:00 2026-06-15T02:21:20+00:00

am creating an analysis system using JFreechart Library and I want to have something

  • 0

am creating an analysis system using JFreechart Library and I want to have something like pivot table functionalities like the one in MS excel, I want to Pool a certain database field so that I have Jcheckboxes having the names of each distinct value from the database. I have implemented this using JCombobox like:

Class.forName("oracle.jdbc.driver.OracleDriver");
        dbcon = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:XE", "USERNAME", "PASSWORD");
        Statement st = dbcon.createStatement();
        String combo = "Select DORM_NAME from dormitory_master_table";
        ResultSet res = st.executeQuery(combo);
        Vector v = new Vector();
        while (res.next()) {
            String ids = res.getString("DORM_NAME");
            v.add(ids);


            cboDormitory = new JComboBox(v);

This gets all dorm name into the Jcombobox, but this is ineffective for what I want to do as I need to be able to select multiple objects. How Can i implement this?

  • 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-06-15T02:21:21+00:00Added an answer on June 15, 2026 at 2:21 am

    to clarify do you want multiple JCheckBoxs in a single JComboBox in order to allow multiple selection without having hundreds of JCheckboxs on screen?

    Sounds like work for JList in this case.

    see:

    • How to Use Lists

    A JList will allow multiple selection from a list of values (screenshot taken straight from orcale – How to Use Lists tutorial to illustrate what I mean):

    enter image description here

    Here is a custom example I had which uses JCheckBoxs:

    enter image description here

    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.awt.Rectangle;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import javax.swing.JCheckBox;
    import javax.swing.JFrame;
    import javax.swing.JList;
    import javax.swing.JScrollPane;
    import javax.swing.ListCellRenderer;
    import javax.swing.ListSelectionModel;
    import javax.swing.SwingUtilities;
    import javax.swing.UIManager;
    
    public class JListTest {
    
        public JListTest() {
            JFrame frame = new JFrame();
            frame.setTitle("JList Test");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
            initComponents(frame);
    
            frame.pack();
            frame.setVisible(true);
        }
    
        private void initComponents(JFrame frame) {
            String[] strs = {"swing", "home", "basic", "metal"};
    
            final JList checkBoxesJList = new JList(createData(strs));
            checkBoxesJList.setCellRenderer(new CheckListRenderer());
            checkBoxesJList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    
            checkBoxesJList.addMouseListener(new MouseAdapter() {
                public void mouseClicked(MouseEvent e) {
                    int index = checkBoxesJList.locationToIndex(e.getPoint());
                    CheckableItem item = (CheckableItem) checkBoxesJList.getModel().getElementAt(index);
                    item.setSelected(!item.isSelected());
                    Rectangle rect = checkBoxesJList.getCellBounds(index, index);
                    checkBoxesJList.repaint(rect);
                }
            });
    
            JScrollPane scrollPane = new JScrollPane(checkBoxesJList);
            frame.add(scrollPane, BorderLayout.CENTER);
        }
    
        private CheckableItem[] createData(String[] strs) {
            int n = strs.length;
            CheckableItem[] items = new CheckableItem[n];
            for (int i = 0; i < n; i++) {
                items[i] = new CheckableItem(strs[i]);
            }
            return items;
        }
    
        public static void main(String[] args) {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    new JListTest();
                }
            });
        }
    }
    
    class CheckListRenderer extends JCheckBox implements ListCellRenderer {
    
        public CheckListRenderer() {
            setBackground(UIManager.getColor("List.textBackground"));
            setForeground(UIManager.getColor("List.textForeground"));
        }
    
        @Override
        public Component getListCellRendererComponent(JList list, Object value,
                int index, boolean isSelected, boolean hasFocus) {
            setEnabled(list.isEnabled());
            setSelected(((CheckableItem) value).isSelected());
            setFont(list.getFont());
            setText(value.toString());
            return this;
        }
    }
    
    class CheckableItem {
    
        private String str;
        private boolean isSelected;
    
        public CheckableItem(String str) {
            this.str = str;
            isSelected = false;
        }
    
        public void setSelected(boolean b) {
            isSelected = b;
        }
    
        public boolean isSelected() {
            return isSelected;
        }
    
        @Override
        public String toString() {
            return str;
        }
    }
    

    UPDATE

    as per your comment:

    1) Replace: Vector v = new Vector(); with ArrayList<String> v=new ArrayList<>();

    2) Now edit createData(..) to resemble:

    private CheckableItem[] createData(ArrayList<String> strs) {
        int n = strs.size();
        CheckableItem[] items = new CheckableItem[n];
        for (int i = 0; i < n; i++) {
            items[i] = new CheckableItem(strs.get(i));
        }
        return items;
    }
    

    3) Simply call the createData with reference to ArrayList (which we called v):

    createData(v);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating an Image Processing app that does two image analysis functions. One
I'm creating Analysis Services cubes in Visual Studio BIDS, and have a question about
I was creating a linked server from SQL database to Analysis services using the
I have been set a task of creating a c# console text analysis program.
I'm currently writing an analysis system within which, in the solution, I have created
I have problem in creating modular analysis architecture for C# application. Aim: It is
So What I'm doing is creating an excel file using epplus and saving it
I am creating a line chart from an Analysis Services cube, with a date
Creating a JApplet I have 2 Text Fields, a button and a Text Area.
Creating a simple RPG game, first time using XNA. Trying to get my character

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.