0

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());
    }
}
2
Contributors
3
Replies
5
Views
7 Years
Discussion Span
Last Post by masijade
0

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. :)

Edited by Alex_: n/a

0

Call validate and/or repaint on the JScrollPane.

Edit: Didn't see the edit.

Edited by masijade: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.