Hi,
Recently, I've been working on a JavaFX 2.0. user interface with many
controls and menus.
Wherever there is a MenuBar (whit menus and menuItems) and a Textfield control in the same scene, when I click or call an event on the Textfield the menus and menuItems become unstable. I mean it starts to appear and dissapear with more frequency depending on how many times I clicked on the Textfield.
Also, I've got another problem but I read it was posted before(menuBar doesnt follow the location of the browser while moved or resized):
10120986 ]
I need to know if there is something wrong with my code..
Do I need to add some code, change it or this is a common problem?
I'm currently working on WinXP, netbeans 7.1, javaFX (FXML approach) and google chrome internet browser.
Here is an example:
I downloaded this code from this page and I just added the textField:
[http://marxsoftware.blogspot.com/2012/01/focus-on-javafx-2-fxml-with-netbeans-71.html]
package javafxmenus;
import static java.lang.System.out;
import javafx.application.Application;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.scene.control.*;
import javafx.scene.input.KeyCode;
import javafx.scene.input.KeyCodeCombination;
import javafx.scene.input.KeyCombination;
import javafx.scene.layout.BorderPane;
import javafx.scene.paint.Color;
import javafx.stage.Stage;
/**
* Example of creating menus in JavaFX.
*
* @author Dustin
*/
public class JavaFXMenus extends Application
{
/**
* Build menu bar with included menus for this demonstration.
*
* @param menuWidthProperty Width to be bound to menu bar width.
* @return Menu Bar with menus included.
*/
private MenuBar buildMenuBarWithMenus(final ReadOnlyDoubleProperty menuWidthProperty)
{
final MenuBar menuBar = new MenuBar();
// Prepare left-most 'File' drop-down menu
final Menu fileMenu = new Menu("File");
fileMenu.getItems().add(new MenuItem("New"));
fileMenu.getItems().add(new MenuItem("Open"));
fileMenu.getItems().add(new MenuItem("Save"));
fileMenu.getItems().add(new MenuItem("Save As"));
fileMenu.getItems().add(new SeparatorMenuItem());
fileMenu.getItems().add(new MenuItem("Exit"));
menuBar.getMenus().add(fileMenu);
// Prepare 'Examples' drop-down menu
final Menu examplesMenu = new Menu("JavaFX 2.0 Examples");
examplesMenu.getItems().add(new MenuItem("Text Example"));
examplesMenu.getItems().add(new MenuItem("Objects Example"));
examplesMenu.getItems().add(new MenuItem("Animation Example"));
menuBar.getMenus().add(examplesMenu);
// Prepare 'Help' drop-down menu
final Menu helpMenu = new Menu("Help");
final MenuItem searchMenuItem = new MenuItem("Search");
searchMenuItem.setDisable(true);
helpMenu.getItems().add(searchMenuItem);
final MenuItem onlineManualMenuItem = new MenuItem("Online Manual");
onlineManualMenuItem.setVisible(false);
helpMenu.getItems().add(onlineManualMenuItem);
helpMenu.getItems().add(new SeparatorMenuItem());
final MenuItem aboutMenuItem =
MenuItemBuilder.create()
.text("About")
.onAction(
new EventHandler<ActionEvent>()
{
@Override public void handle(ActionEvent e)
{
out.println("You clicked on About!");
}
})
.accelerator(
new KeyCodeCombination(
KeyCode.A, KeyCombination.CONTROL_DOWN))
.build();
helpMenu.getItems().add(aboutMenuItem);
menuBar.getMenus().add(helpMenu);
// bind width of menu bar to width of associated stage
menuBar.prefWidthProperty().bind(menuWidthProperty);
return menuBar;
}
@Override
public void start(final Stage stage)
{
stage.setTitle("Creating Menus with JavaFX 2.0");
final Group rootGroup = new Group();
final Scene scene = new Scene(rootGroup, 800, 400, Color.WHEAT);
final BorderPane border = new BorderPane();
final MenuBar menuBar = buildMenuBarWithMenus(stage.widthProperty());
final TextField lolo= new TextField ();
final Button a = new Button ("Button1");
final Button b = new Button ("Button2");
final Button c = new Button ("Button3");
final Button d = new Button ("Button4");
border.setTop(menuBar);
border.setCenter(b);
border.setRight(lolo);
border.setLeft(d);
border.setBottom(a);
rootGroup.getChildren().add(border);
stage.setScene(scene);
stage.show();
}
/**
* Main executable function for running examples.
*
* @param arguments Command-line arguments: none expected.
*/
public static void main(final String[] arguments)
{
Application.launch(arguments);
}
}
PD: Please forgive me for my bad english.
Edited by: 912422 on 05-feb-2012 16:15
Edited by: 912422 on 05-feb-2012 16:23
Edited by: Sephirot on Feb 6, 2012 6:27 AM
Edited by: Sephirot on Feb 6, 2012 6:29 AM
Edited by: Sephirot on Feb 6, 2012 9:39 AM