I have a class that gets a JFrame as a parameter. I want to get a certain component from it and do some operations with it.
Something like this:

class A {
    A (JFrame frame){
        a_certain_Component jScrollPane = (a_certain_Component) frame.getThatComponent();
        jScrollPane.setViewPort(new JTextPane());
    }
}

getComponents and instanceof

Hey thanks. But i still can't add something to the scroll pane.
my code

Component[] comps = theFrame.getContentPane().getComponents();
        int i =-1;
        do{i++; }while(!(comps[i] instanceof JScrollPane) );
        JScrollPane scrollPane = (JScrollPane) comps[i];
        JTextArea ta = new JTextArea ("texttttt");
        ta.setText("testsetsetsetsetset");
        scrollPane.add(ta);
        scrollPane.setViewportView(ta);

Can you please tell me what i'm missing?

[EDIT]
Nevermind. I fixed it. :)

Call validate and/or repaint on the JScrollPane.

Edit: Didn't see the edit.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.