[英]how to set position of value of JSpinner
我在我的Java代码中使用了JSpinner,在JSpinner中,JSpinner的值显示在JSpinner的右侧,但我希望JSpinner的值应出现在JSpinner的左侧,所以请告诉我该怎么做那???
Have you tried getting the JSpinner's editor via getEditor(), and then from that getting its textfield via getTextField(). 您是否尝试过通过getEditor()获取JSpinner的编辑器,然后通过getTextField()从中获取其文本字段。 You could probably set its orientation. 您可能可以设置其方向。
import javax.swing.*;
import javax.swing.JSpinner.DefaultEditor;
public class OppositeSpinner {
public static void main(String[] args) {
JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 1));
JFormattedTextField textField = ((DefaultEditor) spinner.getEditor()).getTextField();
textField.setHorizontalAlignment(JTextField.LEFT);
JOptionPane.showMessageDialog(null, spinner);
}
}
Alternatively, you could change the Look and Feel's value for the Spinner.editorAlignment
property via the UIManager.put(...)
method. 另外,您可以通过UIManager.put(...)
方法更改Spinner.editorAlignment
属性的外观值。 eg, 例如,
UIManager.put("Spinner.editorAlignment", JTextField.LEFT);
For a more complete example: 有关更完整的示例:
public static void main(String[] args) {
UIManager.put("Spinner.editorAlignment", JTextField.LEFT);
JSpinner spinner = new JSpinner(new SpinnerNumberModel(50, 0, 100, 1));
JOptionPane.showMessageDialog(null, spinner);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.