我是Swing Java开发的新手。有人能帮我这个忙吗。
我有一个带有maskformatter的jformattedtextfield文本字段。它工作得很好。但我唯一想知道的是,我们是否可以从正确的位置输入数字。下面的代码可以很好地从左到右输入数字。
谢谢您抽时间见我。
下面是我的java代码:
public class MaskFormattedTextExample extends JFrame {
private static final long serialVersionUID = -1212313123;
JFormattedTextField timeField;
public MaskFormattedTextExample() {
initComponents();
}
private void initComponents() {
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(new Dimension(200, 200));
getContentPane().setLayout(new FlowLayout(FlowLayout.LEFT));
MaskFormatter mask = null;
try {
mask = new MaskFormatter("##:##:##");
mask.setPlaceholderCharacter('_');
} catch (ParseException e) {
e.printStackTrace();
}
timeField = new JFormattedTextField(mask);
timeField.setHorizontalAlignment(JTextField.RIGHT);
timeField.setCaretPosition(JTextField.RIGHT);
getContentPane().add(timeField);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new MaskFormattedTextExample().setVisible(true);
}
});
}
}发布于 2012-12-01 01:16:51
您可以使用:
timeField.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);https://stackoverflow.com/questions/13649810
复制相似问题