-
Bug
-
Resolution: Won't Fix
-
P4
-
None
-
8
-
x86
-
generic
FULL PRODUCT VERSION :
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
When using button bar with buttons with different lengths, the width of the bar is less than needed. Hides some of the buttons.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package sample.test.project.local;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
public class JavaFXTestApplication extends Application {
public JavaFXTestApplication() {
}
@Override public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(getContentPane());
primaryStage.setTitle("ButtonBar Test Program");
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.setOnCloseRequest((e) -> System.exit(0));
for (int n = 9; n < 11; n++) {
Stage stage = new Stage();
stage.setScene(new Scene(getContentPane1(n, stage)));
stage.sizeToScene();
stage.show();
}
primaryStage.show();
}
private BorderPane getContentPane() {
return new BorderPane(new Label("ButtonBar has an issue"));
}
public Parent getContentPane1(int n, Stage stage) {
// ButtonBar buttonBar = new ButtonBar() {
// @Override protected double computePrefWidth(double height) {
// resizeButtons();
// double w = super.computePrefWidth(height);
// System.out.println("computePrefWidth(" + w + ")");
// return w;
// }
//
// private void resizeButtons() {
// final List<? extends Node> buttons =getButtons();
//
// // determine the widest button
// double widest = -1;
// for (Node button : buttons) {
// if (ButtonBar.isButtonUniformSize(button)) {
// widest = Math.max(button.prefWidth(-1), widest);
// }
// }
//
// // set the width of all buttons
// for (Node button : buttons) {
// if (ButtonBar.isButtonUniformSize(button)) {
// sizeButton(button, widest);
// }
// }
// }
//
// private void sizeButton(Node btn, double pref) {
// if (btn instanceof Region) {
// Region regionBtn = (Region) btn;
//
// regionBtn.setPrefWidth(pref);
// }
// }
//
// };
//
ButtonBar buttonBar = new ButtonBar();
buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE);
for (int i = n; i >= 1; i--) {
buttonBar.getButtons().add(createButton("ok", "OK", true, "" + i));
}
return buttonBar;
}
private Node createButton(String name, String toolTip, boolean enabled, String buttonText) {
Button button = new Button();
button.setId(name + "Button");
button.setTooltip(new Tooltip(toolTip));
if (buttonText != null) {
button.setText(buttonText);
}
button.setDisable(!enabled);
button.setMinWidth(Region.USE_PREF_SIZE);
return button;
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Calling resizeButtons() before calling computePrefWidth seems to solve the issue. See the commented code in the source.
java version "1.8.0_131"
Java(TM) SE Runtime Environment (build 1.8.0_131-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.131-b11, mixed mode)
ADDITIONAL OS VERSION INFORMATION :
Microsoft Windows [Version 10.0.14393]
A DESCRIPTION OF THE PROBLEM :
When using button bar with buttons with different lengths, the width of the bar is less than needed. Hides some of the buttons.
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
package sample.test.project.local;
import javafx.application.Application;
import javafx.scene.Node;
import javafx.scene.Parent;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ButtonBar;
import javafx.scene.control.Label;
import javafx.scene.control.Tooltip;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Region;
import javafx.stage.Stage;
public class JavaFXTestApplication extends Application {
public JavaFXTestApplication() {
}
@Override public void start(Stage primaryStage) throws Exception {
Scene scene = new Scene(getContentPane());
primaryStage.setTitle("ButtonBar Test Program");
primaryStage.setScene(scene);
primaryStage.sizeToScene();
primaryStage.setOnCloseRequest((e) -> System.exit(0));
for (int n = 9; n < 11; n++) {
Stage stage = new Stage();
stage.setScene(new Scene(getContentPane1(n, stage)));
stage.sizeToScene();
stage.show();
}
primaryStage.show();
}
private BorderPane getContentPane() {
return new BorderPane(new Label("ButtonBar has an issue"));
}
public Parent getContentPane1(int n, Stage stage) {
// ButtonBar buttonBar = new ButtonBar() {
// @Override protected double computePrefWidth(double height) {
// resizeButtons();
// double w = super.computePrefWidth(height);
// System.out.println("computePrefWidth(" + w + ")");
// return w;
// }
//
// private void resizeButtons() {
// final List<? extends Node> buttons =getButtons();
//
// // determine the widest button
// double widest = -1;
// for (Node button : buttons) {
// if (ButtonBar.isButtonUniformSize(button)) {
// widest = Math.max(button.prefWidth(-1), widest);
// }
// }
//
// // set the width of all buttons
// for (Node button : buttons) {
// if (ButtonBar.isButtonUniformSize(button)) {
// sizeButton(button, widest);
// }
// }
// }
//
// private void sizeButton(Node btn, double pref) {
// if (btn instanceof Region) {
// Region regionBtn = (Region) btn;
//
// regionBtn.setPrefWidth(pref);
// }
// }
//
// };
//
ButtonBar buttonBar = new ButtonBar();
buttonBar.setButtonMinWidth(Region.USE_PREF_SIZE);
for (int i = n; i >= 1; i--) {
buttonBar.getButtons().add(createButton("ok", "OK", true, "" + i));
}
return buttonBar;
}
private Node createButton(String name, String toolTip, boolean enabled, String buttonText) {
Button button = new Button();
button.setId(name + "Button");
button.setTooltip(new Tooltip(toolTip));
if (buttonText != null) {
button.setText(buttonText);
}
button.setDisable(!enabled);
button.setMinWidth(Region.USE_PREF_SIZE);
return button;
}
public static void main(String[] args) {
launch(args);
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
Calling resizeButtons() before calling computePrefWidth seems to solve the issue. See the commented code in the source.