私はSwing Java開発の新人です。私はこれを手伝ってくれますか?Swing - MaskFormatter - テキストフィールドの右側から数値を入力してください
私は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);
}
});
}
}
あなたは(http://docs.oracle [ '' setComponentOrientation(ComponentOrientationを0)]みました.com/javase/1.4.2/docs/api/javax/swing/JSpinner.html)メソッド? – fireshadow52
['Component.setComponentOrientation(ComponentOrientation)'](http://docs.oracle.com/javase/6/docs/api/java/awt/Component.html#setComponentOrientation%28java.awt.ComponentOrientation%29)FTFY @ fireshadow52 :) – Brian
ブライアンとfireshadow52ありがとうございます。それは良い作品です。しかし、小さな問題が1つあります。キャレットの位置はちょっと混乱しています。私はいつも最後にキャレットポジションを見たいと思う。代わりに最初に表示されます。また、3桁の数字を入力した後の数字のフォーマットは149です(1:49と表示されますが、14:9と表示されます) – Steve