swtページ内の単一のコンポジットから特定のコントロールタイプ(すべてのボタンなど)を取得するにはどうすればよいですか?特定のコントロールタイプのコンポジットからすべてのコントロールを取得する
よろしく うーん...
swtページ内の単一のコンポジットから特定のコントロールタイプ(すべてのボタンなど)を取得するにはどうすればよいですか?特定のコントロールタイプのコンポジットからすべてのコントロールを取得する
よろしく うーん...
hereを示すように、あなたはINSTANCEOFキーワードgetComponentsと使用を使用することができます。
Component[] components = this.getComponents();
List<Component> buttons = new ArrayList<Component>();
for (Component component : components)
{
if (component instanceof JButton)
{
buttons.add(component);
}
}
それらが構築されているときにコレクションに追加、またはあなたのUIのすべてのコンポーネントを得るためにあなたのトップレベルのコンテナにgetComponentsを使用しています。その後、便宜のために、タイプ別にコントロールのコレクションに参照を戻すgetAllButtons()
のようなアクセサメソッドを提供します。
必要に応じて、あなたがサポートする必要がある任意のコンポーネント/コントロールタイプのための方法
getAllButtons() // returns an array, LinkedList, or other collection of all Buttons
addButton(Button) // adds a specific, new Button to the global list of Buttons
removeButton(Button) // removes a specific, existing Button from the global list
removeAllButtons() // clears the global list of Buttons
を繰り返し、以下のリストのようなものがあるかもしれません。