I am attempting to align my TextField to print text/numbers from the right however, I am getting an syntax error saying "RIGHT cannot be resolved or is not a field." I did look up similar problems but could not find a solution to my problem.
GridBagConstraints g = new GridBagConstraints();
TextField textField = new TextField(12);
textField.setBackground(Color.white);
Font font = new Font("",Font.PLAIN,46);
textField.setFont(font);
g.insets = new Insets(10,10,350,10);
g.gridx = 0;
g.gridy = 2;
g.ipady = 0;
textField.setHorizontalAlignment(TextField.RIGHT);//Error on this line.
panel.add(textField,g);
enter code here
According with JTextFieldDocumentation the method setHorizontalAlignment
is expecting an int
argument, try this:
textField.setHorizontalAlignment(JTextField.RIGHT);
or this:
textField.setHorizontalAlignment(SwingConstants.RIGHT);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.