Details
-
Bug
-
Resolution: Fixed
-
P3
-
8, 9
-
b09
-
generic
-
generic
Description
FULL PRODUCT VERSION :
1.8.0_121-b13
ADDITIONAL OS VERSION INFORMATION :
Tested on Xubuntu 16.04 and Mac OS-X.
EXTRA RELEVANT SYSTEM CONFIGURATION :
Nothing special
A DESCRIPTION OF THE PROBLEM :
TextField setAlignment(Pos.BASELINE_RIGHT) should right align text. If the text is changed after the stage has been shown, the text left-aligns to the left edge of the previous text-field contents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a text field. Set alignment to Pos.BASELINE_RIGHT. Set text in the text field to be something short. Show the stage. Change the text to a long string: note that the long string is left-aligned to a point in the middle of the text field
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If Post.BASELINE_RIGHT is set, the text should always be right-aligned.
ACTUAL -
The text is left-aligned to a point in the middle of the text field.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package Bug;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class TextFieldBug extends Application {
private final String SHORT_TEXT = "A short text";
private final String LONG_TEXT = "Long text this is a long text this is a long text";
private Label lblLeft = new Label("Left justified");
private TextField txtLeftShort = new TextField(SHORT_TEXT);
private TextField txtLeftLong = new TextField(SHORT_TEXT);
private Label lblRight = new Label("Right justified");
private TextField txtRightShort = new TextField(SHORT_TEXT);
private TextField txtRightLong = new TextField(SHORT_TEXT);
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
GridPane root = new GridPane();
root.addColumn(0, lblLeft, txtLeftShort, txtLeftLong);
root.addColumn(1, lblRight, txtRightShort, txtRightLong);
lblLeft.setAlignment(Pos.BASELINE_LEFT);
txtLeftShort.setAlignment(Pos.BASELINE_LEFT);
txtLeftLong.setAlignment(Pos.BASELINE_LEFT);
lblRight.setMaxWidth(9999);
lblRight.setAlignment(Pos.BASELINE_RIGHT);
txtRightShort.setAlignment(Pos.BASELINE_RIGHT);
txtRightLong.setAlignment(Pos.BASELINE_RIGHT);
Scene scene = new Scene(root, 300, 200);
primaryStage.setScene(scene);
primaryStage.setTitle("Text field alignment bug");
primaryStage.show();
// Changing text after "show"
txtLeftLong.setText(LONG_TEXT);
txtRightLong.setText(LONG_TEXT);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
After setting the text, change the alignment to Pos.BASELINE_LEFT, then change it back to Pos.BASELINE_RIGHT
1.8.0_121-b13
ADDITIONAL OS VERSION INFORMATION :
Tested on Xubuntu 16.04 and Mac OS-X.
EXTRA RELEVANT SYSTEM CONFIGURATION :
Nothing special
A DESCRIPTION OF THE PROBLEM :
TextField setAlignment(Pos.BASELINE_RIGHT) should right align text. If the text is changed after the stage has been shown, the text left-aligns to the left edge of the previous text-field contents.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a text field. Set alignment to Pos.BASELINE_RIGHT. Set text in the text field to be something short. Show the stage. Change the text to a long string: note that the long string is left-aligned to a point in the middle of the text field
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
If Post.BASELINE_RIGHT is set, the text should always be right-aligned.
ACTUAL -
The text is left-aligned to a point in the middle of the text field.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package Bug;
import javafx.application.Application;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Label;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.stage.Stage;
public class TextFieldBug extends Application {
private final String SHORT_TEXT = "A short text";
private final String LONG_TEXT = "Long text this is a long text this is a long text";
private Label lblLeft = new Label("Left justified");
private TextField txtLeftShort = new TextField(SHORT_TEXT);
private TextField txtLeftLong = new TextField(SHORT_TEXT);
private Label lblRight = new Label("Right justified");
private TextField txtRightShort = new TextField(SHORT_TEXT);
private TextField txtRightLong = new TextField(SHORT_TEXT);
public static void main(String[] args) {
launch();
}
@Override
public void start(Stage primaryStage) throws Exception {
GridPane root = new GridPane();
root.addColumn(0, lblLeft, txtLeftShort, txtLeftLong);
root.addColumn(1, lblRight, txtRightShort, txtRightLong);
lblLeft.setAlignment(Pos.BASELINE_LEFT);
txtLeftShort.setAlignment(Pos.BASELINE_LEFT);
txtLeftLong.setAlignment(Pos.BASELINE_LEFT);
lblRight.setMaxWidth(9999);
lblRight.setAlignment(Pos.BASELINE_RIGHT);
txtRightShort.setAlignment(Pos.BASELINE_RIGHT);
txtRightLong.setAlignment(Pos.BASELINE_RIGHT);
Scene scene = new Scene(root, 300, 200);
primaryStage.setScene(scene);
primaryStage.setTitle("Text field alignment bug");
primaryStage.show();
// Changing text after "show"
txtLeftLong.setText(LONG_TEXT);
txtRightLong.setText(LONG_TEXT);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
After setting the text, change the alignment to Pos.BASELINE_LEFT, then change it back to Pos.BASELINE_RIGHT
Attachments
Issue Links
- relates to
-
JDK-8301898 Input method decoration fails to honor Alignment property
- Open