java settext用法_Java JFormattedTextField.setText方法代码示例

import javax.swing.JFormattedTextField; //导入方法依赖的package包/类

/**

* Creates a {@link JFormattedTextField} for the specified cell. If a formatter is given, will

* apply it to the field. Does not validate the model, so make sure this call works!

*

* @param model

* @param rowIndex

* @param columnIndex

* @param cellClass

* @param formatter

* the formatter or null if none is required

* @param hideUnavailableContentAssist

* @return

*/

public CellTypeTextFieldDefaultImpl(final TablePanelModel model, final int rowIndex, final int columnIndex,

final Class extends CellType> cellClass, AbstractFormatter formatter, boolean hideUnavailableContentAssist) {

super();

final JFormattedTextField field = CellTypeImplHelper.createFormattedTextField(model, rowIndex, columnIndex);

setLayout(new BorderLayout());

add(field, BorderLayout.CENTER);

// otherwise 'null' would be restored

Object value = model.getValueAt(rowIndex, columnIndex);

String text = value != null ? String.valueOf(value) : "";

// specical handling when formatter is given

if (formatter != null) {

field.setFormatterFactory(new DefaultFormatterFactory(formatter));

}

field.setText(text);

// set syntax assist if available

String syntaxHelp = model.getSyntaxHelpAt(rowIndex, columnIndex);

if (syntaxHelp != null && !"".equals(syntaxHelp.trim())) {

PromptSupport.setForeground(Color.LIGHT_GRAY, field);

PromptSupport.setPrompt(syntaxHelp, field);

PromptSupport.setFontStyle(Font.ITALIC, field);

PromptSupport.setFocusBehavior(FocusBehavior.SHOW_PROMPT, field);

}

// see if content assist is possible for this field, if so add it

ImageIcon icon = SwingTools.createIcon("16/"

+ I18N.getMessageOrNull(I18N.getGUIBundle(), "gui.action.content_assist.icon"));

JButton contentAssistButton = new JButton();

contentAssistButton.setIcon(icon);

if (field.isEnabled() && model.isContentAssistPossibleForCell(rowIndex, columnIndex)) {

contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),

"gui.action.content_assist_enabled.tip"));

CellTypeImplHelper.addContentAssist(model, rowIndex, columnIndex, field, contentAssistButton, cellClass);

} else {

contentAssistButton.setToolTipText(I18N.getMessageOrNull(I18N.getGUIBundle(),

"gui.action.content_assist_disabled.tip"));

contentAssistButton.setEnabled(false);

}

if (contentAssistButton.isEnabled() || (!contentAssistButton.isEnabled() && !hideUnavailableContentAssist)) {

add(contentAssistButton, BorderLayout.EAST);

}

// set size so panels don't grow larger when they get the chance

setPreferredSize(new Dimension(300, 20));

setMinimumSize(new Dimension(100, 15));

setMaximumSize(new Dimension(1600, 30));

}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值