JScrollPane not showing checkboxes...

This code:

   /**
     * This method initializes jScrollPane3
     *
     * @return javax.swing.JScrollPane
     */
    private JScrollPane getJScrollPane3() {
        if (jScrollPane3 == null) {
            jScrollPane3 = new JScrollPane();
            try {
                Set methods = GetTestMethods.findMethods(DeviceIdentification.class);
                System.out.println(methods.size());
                for (Iterator it = methods.iterator(); it.hasNext();) {
                    Object listElement = it.next();
                    String element = listElement.toString();
                    System.out.println(element);
                    JCheckBox newCheckBox = new JCheckBox();
                    newCheckBox.setName(element);
                    System.out.println(newCheckBox.getName());
                    jScrollPane3.add(newCheckBox);
                }
            } catch (Exception e) {
                atelog.error(e);
                e.printStackTrace();
            }
        }
        return jScrollPane3;
    }

Doesn't materialize any check boxes in my jScrollPane......

I've doen a sysout to see if the jCheckBoxes are getting set and they are. Am I missing something here?

I tried setEnabled and setVisible, still nothing.

Thanks!
LVL 2
k41d3nAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
           try {
                JPanel panel = new JPanel();
                Set methods = GetTestMethods.findMethods(DeviceIdentification.class);
                System.out.println(methods.size());
                for (Iterator it = methods.iterator(); it.hasNext();) {
                    Object listElement = it.next();
                    String element = listElement.toString();
                    System.out.println(element);
                    JCheckBox newCheckBox = new JCheckBox();
                    newCheckBox.setName(element);
                    System.out.println(newCheckBox.getName());
                    panel.add(newCheckBox);
                }
                jScrollPane3.setViewportView(panel);
            } catch (Exception e) {
                atelog.error(e);
                e.printStackTrace();
            }
0
 
hkang042997Commented:
What does the Set statement in the following do?

               Set methods = GetTestMethods.findMethods(DeviceIdentification.class);

It looks like a VB statement rather than a Java one.

0
 
hkang042997Commented:
I see.  It's a collection.
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
objectsCommented:
You cannot add components to a scroll pane, instead you should add them to a JPanel and put your panel in your scroll pane using:

jScrollPane3.setViewportView(panel);
0
 
limaidealCommented:
That's right, first of all you cannot add component directly to scroll pane.

Normally you need to create another panel with correct layout manager to hold the checkboxes( such as grid layout ), then call scrollPane.getViewPort().add(theOtherPanel) to add it in.
0
 
limaidealCommented:
it is actually scrollPane.getViewPort().add(theOtherPanel, null)
0
 
k41d3nAuthor Commented:
Boo yah,

Here is what I got:

   /**
     * This method initializes jScrollPane3
     *
     * @return javax.swing.JScrollPane
     */
    private JScrollPane getJScrollPane3() {
        if (jScrollPane3 == null) {
            jScrollPane3 = new JScrollPane();
            jScrollPane3.setViewportView(getJPaneCheckBox());
        }
        return jScrollPane3;
    }

   private JPanel getJPaneCheckBox() {
        JPanel jPanelCheckBox = new JPanel();  
        GridLayout checkbox = new GridLayout(1, 2);
        jPanelCheckBox.setLayout(checkbox);
        try {
            Set methods = GetTestMethods
            .findMethods(DeviceIdentification.class);
            System.out.println(methods.size());
            //these variables are defined private elsewhere in the class
            //For a set or list
            for (Iterator it = methods.iterator(); it.hasNext();) {
                Object listElement = it.next();
                String element = listElement.toString();
                System.out.println(element);
                JCheckBox newCheckBox = new JCheckBox();
                newCheckBox.setName(element);
                System.out.println(newCheckBox.getName());
                jPanelCheckBox.add(newCheckBox);
            }
        } catch (Exception e) {
            atelog.error(e);
            e.printStackTrace();
        }
        return(jPanelCheckBox);
    }

I have more questions, But those require more points.

Thanks again.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.