-
Bug
-
Resolution: Cannot Reproduce
-
P3
-
None
-
8u40
-
Netbeans 8, Java 8, Scene Builder 2.0, Windows 7, 64-bit.
Hello all,
Sorry for the vague title, but I really couldn't think of a good title for this issue, so I will explain it now.
I created a custom control and I was setting it to my scene. I added my scene to my stage and got a huge scene for some reason which was odd.
I then tried to manually set the scene's width and height to the value of my control
scene = new Scene(login, login.getWidth(), login.getHeight());
but for some reason the error still persisted, the scene was still big. I tried some printlns and found that my values for height and width were 0, max height was -1.
I then looked at my FXML file and saw that it defines "prefHeight" even though in Scene Builder there are disabled width/height TextFields that corresponds to the prefWidth/Height.
I then tried the pref values and it worked.
Originally height and width were 0, but for some reason, when setting the scene to prefWidth and Height, for some reason the logincontrol's width and height now equal the prefwidth/height...
This is very weird, and I think it's a bug and should be fixed. This also makes sense why the scene wasn't the size of my custom control. It was using the values for width/height most likely, and not the pref ones.
Here is my code.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uploader;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author Konrad
*/
public class Uploader extends Application
{
LoginControl login = new LoginControl();
UsersControl users = new UsersControl();
// PlansController plans = new PlansController();
Scene scene;
@Override
public void start(Stage stage) throws Exception
{
scene = new Scene(login, login.getWidth(), login.getHeight());
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
stage.setScene(scene);
stage.setTitle("Custom Control");
stage.setWidth(scene.getWidth());
stage.setHeight(scene.getHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
0.0???? fsdjaflksdja 227.0????
0.0 fsdjaflksdja -1.0
0.0 fsdjaflksdja 0.0
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
227.0???? fsdjaflksdja 227.0??????
227.0 fsdjaflksdja -1.0
227.0 fsdjaflksdja 221.0
Thanks all
EDIT: login.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<fx:root id="root" prefHeight="221.0" prefWidth="227.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="TRANSPARENT" height="217.0" layoutX="2.0" layoutY="2.0" stroke="BLACK" strokeType="INSIDE" width="224.0" />
<Button fx:id="submit" layoutX="39.0" layoutY="170.0" mnemonicParsing="false" onAction="#login" prefHeight="25.0" prefWidth="149.0" text="Login" />
<TextField fx:id="company" layoutX="40.0" layoutY="33.0" promptText="Company Name" />
<TextField fx:id="user" layoutX="40.0" layoutY="68.0" promptText="User Name" />
<CheckBox fx:id="remember" layoutX="40.0" layoutY="140.0" mnemonicParsing="false" text="Remember Me" />
<PasswordField fx:id="password" layoutX="40.0" layoutY="103.0" promptText="Password" />
</children>
</fx:root>
LoginControl.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uploader;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
/**
*
* @author Konrad
*/
public class LoginControl extends AnchorPane
{
@FXML
private Button submit;
@FXML
private TextField company;
@FXML
private TextField user;
@FXML
private TextField password;
@FXML
private CheckBox remember;
@FXML
private void login()
{
}
public LoginControl()
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("login.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try
{
fxmlLoader.load();
}
catch (IOException exception)
{
throw new RuntimeException(exception);
}
}
}
Sorry for the vague title, but I really couldn't think of a good title for this issue, so I will explain it now.
I created a custom control and I was setting it to my scene. I added my scene to my stage and got a huge scene for some reason which was odd.
I then tried to manually set the scene's width and height to the value of my control
scene = new Scene(login, login.getWidth(), login.getHeight());
but for some reason the error still persisted, the scene was still big. I tried some printlns and found that my values for height and width were 0, max height was -1.
I then looked at my FXML file and saw that it defines "prefHeight" even though in Scene Builder there are disabled width/height TextFields that corresponds to the prefWidth/Height.
I then tried the pref values and it worked.
Originally height and width were 0, but for some reason, when setting the scene to prefWidth and Height, for some reason the logincontrol's width and height now equal the prefwidth/height...
This is very weird, and I think it's a bug and should be fixed. This also makes sense why the scene wasn't the size of my custom control. It was using the values for width/height most likely, and not the pref ones.
Here is my code.
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uploader;
import javafx.application.Application;
import javafx.scene.Scene;
import javafx.stage.Stage;
/**
*
* @author Konrad
*/
public class Uploader extends Application
{
LoginControl login = new LoginControl();
UsersControl users = new UsersControl();
// PlansController plans = new PlansController();
Scene scene;
@Override
public void start(Stage stage) throws Exception
{
scene = new Scene(login, login.getWidth(), login.getHeight());
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
stage.setScene(scene);
stage.setTitle("Custom Control");
stage.setWidth(scene.getWidth());
stage.setHeight(scene.getHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
stage.show();
}
/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
launch(args);
}
}
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
0.0???? fsdjaflksdja 227.0????
0.0 fsdjaflksdja -1.0
0.0 fsdjaflksdja 0.0
System.out.println(login.getWidth() + " fsdjaflksdja " + login.getPrefWidth());
System.out.println(scene.getWidth() + " fsdjaflksdja " + login.getMaxHeight());
System.out.println(stage.getWidth() + " fsdjaflksdja " + stage.getHeight());
227.0???? fsdjaflksdja 227.0??????
227.0 fsdjaflksdja -1.0
227.0 fsdjaflksdja 221.0
Thanks all
EDIT: login.fxml
<?xml version="1.0" encoding="UTF-8"?>
<?import javafx.scene.shape.*?>
<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<fx:root id="root" prefHeight="221.0" prefWidth="227.0" type="javafx.scene.layout.AnchorPane" xmlns="http://javafx.com/javafx/8" xmlns:fx="http://javafx.com/fxml/1">
<children>
<Rectangle arcHeight="5.0" arcWidth="5.0" fill="TRANSPARENT" height="217.0" layoutX="2.0" layoutY="2.0" stroke="BLACK" strokeType="INSIDE" width="224.0" />
<Button fx:id="submit" layoutX="39.0" layoutY="170.0" mnemonicParsing="false" onAction="#login" prefHeight="25.0" prefWidth="149.0" text="Login" />
<TextField fx:id="company" layoutX="40.0" layoutY="33.0" promptText="Company Name" />
<TextField fx:id="user" layoutX="40.0" layoutY="68.0" promptText="User Name" />
<CheckBox fx:id="remember" layoutX="40.0" layoutY="140.0" mnemonicParsing="false" text="Remember Me" />
<PasswordField fx:id="password" layoutX="40.0" layoutY="103.0" promptText="Password" />
</children>
</fx:root>
LoginControl.java
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package uploader;
import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.CheckBox;
import javafx.scene.control.TextField;
import javafx.scene.layout.AnchorPane;
import org.apache.shiro.config.IniSecurityManagerFactory;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.util.Factory;
/**
*
* @author Konrad
*/
public class LoginControl extends AnchorPane
{
@FXML
private Button submit;
@FXML
private TextField company;
@FXML
private TextField user;
@FXML
private TextField password;
@FXML
private CheckBox remember;
@FXML
private void login()
{
}
public LoginControl()
{
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("login.fxml"));
fxmlLoader.setRoot(this);
fxmlLoader.setController(this);
try
{
fxmlLoader.load();
}
catch (IOException exception)
{
throw new RuntimeException(exception);
}
}
}