Мне нужны кнопки, которые состоят из нескольких строк, потому что текст некоторых из них длинный. Я попытался расширить CheckBox для создания SpanToggleCheckBox, но он не работает, потому что текст не отображается. Что не так в следующем коде? Как я могу достичь своей цели?
public class SpanToggleCheckBox extends CheckBox {
private TextArea textArea;
/**
* Constructs a toggle checkbox with the given text
*
* @param text to display
*/
public SpanToggleCheckBox(String text) {
textArea = new TextArea(getUIManager().localize(text, text));
textArea.setActAsLabel(true);
textArea.setColumns(textArea.getText().length() + 1);
textArea.setUIID("Label");
textArea.setEditable(false);
textArea.setFocusable(false);
this.setUIID("CheckBox");
super.setToggle(true);
}
/**
* {@inheritDoc}
*/
@Override
public void paint(Graphics g) {
getUIManager().getLookAndFeel().drawTextArea(g, textArea);
}
/**
* {@inheritDoc}
*/
@Override
protected Dimension calcPreferredSize() {
return getUIManager().getLookAndFeel().getTextAreaSize(textArea, true);
}
/**
* Shorthand for creating the SpanToggleCheckBox
*
* @param text the text for the button
* @return a check box
*/
public static SpanToggleCheckBox createToggle(String text) {
SpanToggleCheckBox cb = new SpanToggleCheckBox(text);
return cb;
}
}