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());

Recommended Answers

getComponents and instanceof

Jump to Post

All 3 Replies

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");

Can you please tell me what i'm missing?

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 1.18 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.