• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Need to have customizable pane with Java code

 
Jeyaganeshan Jeyatharsini
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>

<Pane maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.routefinder.srilanka.client.routefinderclient.RouteFinderClient">
<children>
<AnchorPane minHeight="0.0" minWidth="0.0" prefHeight="180.0" prefWidth="200.0">
<children>
<MenuButton layoutX="559.0" layoutY="2.0" mnemonicParsing="false" text=" ">
<items>
<MenuItem mnemonicParsing="false" text="Setting" />
<MenuItem mnemonicParsing="false" text="Sign out" />
</items>
</MenuButton>
<MenuBar layoutY="2.0" prefHeight="25.0" prefWidth="555.0">
<menus>
<Menu mnemonicParsing="false" text="Route Handler">
<items>
<MenuItem mnemonicParsing="false" text="Add New Edge" onAction="#addNewEdge" />
<MenuItem mnemonicParsing="false" text="Edit Existing Edge" onAction="#editEdge" />
<MenuItem mnemonicParsing="false" text="Delete Existing Edge" onAction="#deleteEdge" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="SMS Sender">
<items>
<MenuItem mnemonicParsing="false" text="Send SMS" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="Help" />
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
</children>
</AnchorPane>
<BorderPane id = "customizablePane" layoutX="1.0" layoutY="27.0" prefHeight="374.0" prefWidth="600.0">

</BorderPane>
</children>
</Pane>

I like to customize the BorderPane with Java code as follows:

public class RouteFinderClient implements Initializable{
@FXML
private BorderPane customizablePane;

@Override
public void initialize(URL arg0, ResourceBundle arg1) {
customizablePane = new BorderPane();
}

@FXML
public void addNewEdge()
{
System.out.println("Screen for add edge");
try {
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("com/routefinder/srilanka/client/addroute/AddRoute.fxml"));
Pane myNewPane = (Pane) fxmlLoader.load();
customizablePane.setCenter(myNewPane);
} catch (Exception e) {
e.printStackTrace();
}
}
}

It gives error. Says to set location...
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Same response as your other question:
http://www.coderanch.com/t/638301/JavaFX/java/read-text-textfield-Java

Never create a new node when you already have an FXML injected one.

Remove this line from your code:


Probably you want to do:

instead of:


You might have other issues with your code, I did not check.
 
Jeyaganeshan Jeyatharsini
Greenhorn
Posts: 29
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I remove borderPane = new BorderPane() it gives NULLPointerException...
 
John Damien Smith
Ranch Hand
Posts: 296
14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
> If I remove borderPane = new BorderPane() it gives NULLPointerException...

That is because you have other issues in your code.

You define the pane in FXML, providing only a CSS id and not an FXML id, so the FXML loader has no idea how to link the loaded pane with the customizablePane reference in your controller.

Instead of:

You need:

You might have other issues with your code, I did not check.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic