私はこのような答えを与えて憎むが、この場合には、私はそれが最善であると感じ...
これは非常に非標準のUIコンポーネントのように思えます。
O The weather
O Parties
O meta-science
O pseudo-science
O Animals
ユーザーはあなたが提案されているコンポーネントの種類に精通していないだろう、そしてそれは、リスト内の他のオプションと非常に矛盾している:あなただけやった場合、それははるかに良いUXだろう。私は、より標準的な規則を使用することを強くお勧めします。私のよりよい判決に対して
、私はComboBoxRadioButton
を提示:それは完全ではありません
、また私はそれを使用することをお勧めしますが、それはあなたが望むもののように見えます。
import java.awt.FlowLayout;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JToggleButton;
public class ComboBoxRadioButton extends JRadioButton {
private JLabel beforeText, afterText;
private JComboBox comboBox;
public ComboBoxRadioButton(String beforeTxt, JComboBox comboBox,
String afterText) {
this.comboBox = comboBox;
this.beforeText = new JLabel(" " + beforeTxt);
this.afterText = new JLabel(afterText);
comboBox.setSelectedIndex(0);
setLayout(new FlowLayout());
setModel(new JToggleButton.ToggleButtonModel());
add(this.beforeText);
add(this.comboBox);
add(this.afterText);
}
public static void main(String[] args) {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel mainPane = new JPanel();
ButtonGroup group = new ButtonGroup();
AbstractButton b2 = new JRadioButton("Java Swing");
AbstractButton b3 = new ComboBoxRadioButton(
"It's gonna be a", new JComboBox(new String[] { "good", "bad",
"rainy" }), "day!");
AbstractButton b4 = new JRadioButton("After the combo");
group.add(b2);
group.add(b3);
group.add(b4);
mainPane.add(b2);
mainPane.add(b3);
mainPane.add(b4);
f.add(mainPane);
f.pack();
f.setVisible(true);
}
}
ええ、非標準のUI FTW、どうすればよいですか? :) あなたの解決策は単純ですが、 "たくさんの"オプションについては、他のラジオボタンのオプションが本当に関連していて、適切であると仮定しても、それは実行可能な解決策ではないと思います。 また、私はJava Guruが見栄えの良いコードを投げかけているのを見たいと思っています:) – Juhl
@Juhl、あなたはそれを求めました。それは完全ではなく、私はそれを使用することを提案していません。私の編集を参照してください。 – jjnguy