[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 492
  • Last Modified:

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!
0
k41d3n
Asked:
k41d3n
  • 2
  • 2
  • 2
  • +1
1 Solution
 
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
 
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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
 
objectsCommented:
           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
 
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 2
  • 2
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now