下面列出了怎么用javax.swing.plaf.basic.BasicTextFieldUI的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a new text input field.
*
* @param sheet The sheet to listen to.
* @param consumedType The field to listen to.
* @param alignment The alignment of the field.
* @param editable Whether or not the user can edit this field.
* @param tooltip The tooltip to set.
*/
public PageField(CharacterSheet sheet, String consumedType, int alignment, boolean editable, String tooltip) {
super(getFormatterFactoryForType(sheet.getCharacter(), consumedType), sheet.getCharacter().getValueForID(consumedType));
if (Platform.isLinux()) {
// I override the UI here since the GTK UI on Linux has no way to turn off the border
// around text fields.
setUI(new BasicTextFieldUI());
}
mSheet = sheet;
mConsumedType = consumedType;
setFont(sheet.getScale().scale(UIManager.getFont(Fonts.KEY_FIELD_PRIMARY)));
setBorder(null);
setOpaque(false);
// Just setting opaque to false isn't enough for some reason, so I'm also setting the
// background color to a 100% transparent value.
setBackground(new Color(255, 255, 255, 0));
setHorizontalAlignment(alignment);
setEditable(editable);
setEnabled(editable);
if (editable) {
setForeground(new Color(0, 0, 192));
} else {
setDisabledTextColor(Color.BLACK);
}
setToolTipText(Text.wrapPlainTextForToolTip(tooltip));
mSheet.getCharacter().addTarget(this, mConsumedType);
addPropertyChangeListener("value", this);
addActionListener(this);
setFocusLostBehavior(COMMIT_OR_REVERT);
}