0

i am struggling with hiding and showing a label. It seems like if i use the hide() method, the application thread shut down. So when i use my dismiss function i can't switch the visibility to true. I have tried diffrent things, but couldn't figure out where the problems lays.

this is my stage class.

public class NotificationStage extends Application implements MessageReciever {

static Stage          primaryStage;

private static Logger log = LoggerFactory.getLogger( NotificationStage.class );

@Override
public void start( final Stage primaryStage ) throws Exception {
    MasterConsumer.getMasterConsumer().addMessageReciever( this );
    log.info( "Notification added to MessageReciever." );

    log.debug( "initiated starting Stage" );
    NotificationStage.primaryStage = primaryStage;

    Pane root = (Pane) FXMLLoader.load( getClass().getClassLoader().getResource( "Notification.fxml" ) );
    primaryStage.setScene( new Scene( root ) );
    primaryStage.initStyle( StageStyle.UNDECORATED );

    primaryStage.setAlwaysOnTop( true );
    Rectangle2D primaryScreenBounds = Screen.getPrimary().getVisualBounds();

    primaryStage.setX( ( primaryScreenBounds.getMinX() + primaryScreenBounds.getWidth() ) - 394 );
    primaryStage.setY( ( primaryScreenBounds.getMinY() + primaryScreenBounds.getHeight() ) - 102 );

    log.debug( "stage initiliazed" );

    primaryStage.show();

}

public static void dismiss() {
    log.debug( "try to dismiss stage" );
    if ( isTrayShowing() ) {
        primaryStage.hide();
        log.debug( "dismissed stage" );
    }
}

public static boolean isTrayShowing() {
    return NotificationStage.primaryStage.isShowing();
}

public static void show() {
    log.debug( "try to show stage" );
    if ( !isTrayShowing() ) {
        NotificationStage.primaryStage.show();
        log.debug( "showing stage" );
    }}

and this is my controller class.

public class Notification implements Initializable, MessageReciever {

private static Logger log                = LoggerFactory.getLogger( Notification.class );

String                infourl            = "/info.png";
String                warningurl         = "/warning.png";
String                errorurl           = "/error.png";
final String          HeroldStartMessage = "Herold started.";
@FXML
Rectangle             rectangleColor;
@FXML
ImageView             imageIcon;
@FXML
Label                 topicLabel;
@FXML
Label                 messageLabel;
@FXML
Label                 closeLabel;
@FXML
AnchorPane            controlAnchor;

public void messageRecieved( final Message message, final Topic topic ) {

    if ( message.getLevel().contains( "info" ) ) {
        log.info( "message level contains info" );
        Notification.this.rectangleColor.setFill( Paint.valueOf( "#1b2db5" ) );
        Notification.this.imageIcon.setImage( new Image( Notification.this.infourl ) );
        log.info( "Color and Image has been changed." );
    } else if ( message.getLevel().contains( "warning" ) ) {
        log.info( "message level contains warning" );
        Notification.this.rectangleColor.setFill( Paint.valueOf( "#f8790b" ) );
        Notification.this.imageIcon.setImage( new Image( Notification.this.warningurl ) );
        log.info( "Color and Image has been changed." );
    } else if ( message.getLevel().contains( "error" ) ) {
        log.info( "message level contains error" );
        Notification.this.rectangleColor.setFill( Paint.valueOf( "#ff0000" ) );
        Notification.this.imageIcon.setImage( new Image( Notification.this.errorurl ) );
        log.info( "Color and Image has been changed." );
    } else {
        //
    }
    log.info( "Try to change text" );
    NotificationStage.show();
    Platform.runLater( new Runnable() {
        @Override
        public void run() {

            Notification.this.topicLabel.setText( message.getHeader() );
            Notification.this.messageLabel.setText( message.getText() );
            log.info( "text was changed" );

        }
    } );
}

@Override
public void initialize( final URL location, final ResourceBundle resources ) {
    this.closeLabel.setOnMouseClicked( e -> NotificationStage.dismiss() );
    this.rectangleColor.setFill( Paint.valueOf( "#1b2db5" ) );
    this.imageIcon.setImage( new Image( this.infourl ) );
    this.topicLabel.setText( "Herold" );
    this.messageLabel.setText( this.HeroldStartMessage );
    MasterConsumer.getMasterConsumer().addMessageReciever( this );
}

}

Tarifc
  • 13
  • 4
  • "hiding and showing a label." You mean set the `javafx.scene.control.Label`'s visibility? That can be done by `label.setVisible(true/false)` – Sunflame Feb 28 '18 at 10:42
  • so u mean, i dont hide the stage, but just the label? – Tarifc Feb 28 '18 at 11:00
  • I tried to use this, but now, when i ste the visibility to false, there still is just a white page shown... – Tarifc Feb 28 '18 at 11:06
  • Then I don't really know want you want...What you want to hide? A `Label` or the `Stage` or what? – Sunflame Feb 28 '18 at 14:01

0 Answers0