Details
Description
The height of a ComboBox's popup is wrong the first time if its preferred width is set. This results in a scrollbar being displayed the first time. This even happens when setViewableRowCount() is called. Subsequent displays of the popup are the correct height. It appears if setWidth() is used instead the desired behavior is seen, but only under Java8.
{code}
package mirror;
import javafx.application.*;
import javafx.collections.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;
public class MirrorCombo extends Application
{
@Override
public void start( Stage stage )
{
stage.setScene( createScene( false ) );
stage.show();
Stage stage2 = new Stage();
stage2.setScene( createScene( true ) );
stage2.setX( stage.getX() + stage.getWidth() );
stage2.setY( stage.getY() );
stage2.show();
}
private Scene createScene( boolean setPrefWidth )
{
final Group group = new Group();
Label c1 = new Label( "NO setPrefWidth" );
c1.setLayoutX( 20 );
ComboBox c2 = new ComboBox();
c2.setVisibleRowCount( 3 );
if ( setPrefWidth )
{
c2.setPrefWidth( 110.0 );
c1.setText( "setPrefWidth" );
}
c2.setItems( FXCollections.observableArrayList( "Fred", "Marry", "Todd" ) );
c2.setLayoutX( 100 );
c2.setLayoutY( 50 );
group.getChildren().addAll( c1, c2 );
Scene scene = new Scene( group, 200, 200 );
return scene;
}
public static void main( String[] args )
{
launch( args );
}
}
{code}
{code}
package mirror;
import javafx.application.*;
import javafx.collections.*;
import javafx.scene.*;
import javafx.scene.control.*;
import javafx.stage.*;
public class MirrorCombo extends Application
{
@Override
public void start( Stage stage )
{
stage.setScene( createScene( false ) );
stage.show();
Stage stage2 = new Stage();
stage2.setScene( createScene( true ) );
stage2.setX( stage.getX() + stage.getWidth() );
stage2.setY( stage.getY() );
stage2.show();
}
private Scene createScene( boolean setPrefWidth )
{
final Group group = new Group();
Label c1 = new Label( "NO setPrefWidth" );
c1.setLayoutX( 20 );
ComboBox c2 = new ComboBox();
c2.setVisibleRowCount( 3 );
if ( setPrefWidth )
{
c2.setPrefWidth( 110.0 );
c1.setText( "setPrefWidth" );
}
c2.setItems( FXCollections.observableArrayList( "Fred", "Marry", "Todd" ) );
c2.setLayoutX( 100 );
c2.setLayoutY( 50 );
group.getChildren().addAll( c1, c2 );
Scene scene = new Scene( group, 200, 200 );
return scene;
}
public static void main( String[] args )
{
launch( args );
}
}
{code}