1

基本的に私はカードを使ったプログラムを持っています (私は CardLayout を使用しています)。入力したフィールドを保存してラベルに変数として配置する方法がわかりません。何か案は?必要に応じてコードを提供できます。

createButton2.addActionListener(new ActionListener() {   //Back button listener, switches back to ADMIN fixtures panel
            @Override
            public void actionPerformed(ActionEvent e) {
                cardLayout.show(container, "6");
                String theText = descriptionField.getText();
                fixtureDescLabel.setText( theText );
                fixtureDescLabel.setBounds(250, 150, 200, 40);
                add(fixtureDescLabel);
            }
        });
4

1 に答える 1

2

それはかなり簡単です。

textArea からテキストを取得します。

String theText = myTextArea.getText();

ラベルを付ける:

myLabel.setText( theText );

ボタン リスナーの場合:

myButton.addActionListener( new ActionListener() {
    @override public actionPerformed( ActionEvent event )
    {
        String theText = myTextArea.getText();
        myLabel.setText( theText );
    }
} );

編集

JFrame#revalidate()編集を見ると、コンポーネントを再検証 ( )せずにフレームに追加することが問題です。

于 2014-02-17T20:52:26.537 に答える