0

JTabbedPane の (複数の) JScrollPane に JTextArea があります。

JTextArea にアクセスする必要があります。JScrollPane がない場合は、次のようにできます。

JTextArea c = (JTextArea)jTabbedPane1.getComponentAt(i);

JScrollPane でどのように取得しますか?

乾杯、ガズラー。

4

3 に答える 3

5

Sounds like you'll get into a mess of references over there ( at least that's what have happened to me in the past ) .

I would suggest you to have a middle object in charge of those dependencies for you and to move the "business" methods there.

So instead of adding components and losing the references ( or worst, duplicating the references all over the place ) you can use this object which will have the reference:

class AppMediator {
     private JTextArea area;
     private JTabbetPane pane;

     // etc. 

     public void doSomethingWithText() {
          this.area.getText(); // etc 
     }
 }

See the Mediator design pattern. The focus is to move all the "view" objects from where they are ( usually as references in subclasses ) to a common intermediate object.

于 2009-12-02T17:22:36.433 に答える
3

この行は複雑に見えますが、これでうまくいくと思います。

JTextArea c = (JTextArea) (((JViewportView) (((JScrollPane) jTabbedPane1.getComponentAt(i)).getViewport()))).getView();

TextAreaしかし、あなたのを に保存する方が面白いと思いますArrayList
だからあなたはこれを行うことができます:

List<JTextArea> listAreas = new ArrayList<JTextArea>();

...
JTextArea c = listAreas.get(i);

新しいものを作成すると、次のようになります。

JTextArea c = new JTextArea();
jTabbedPane1.addTab("Title", new JScrollPane(c));
listAreas.add(c);

お役に立てれば。

于 2009-12-02T17:24:21.480 に答える