From r.lichtenberger at gmail.com Tue Oct 20 08:23:30 2020 From: r.lichtenberger at gmail.com (Robert Lichtenberger) Date: Tue, 20 Oct 2020 10:23:30 +0200 Subject: Default Buttons in Alert API Message-ID: The Alert API allows to specify Button text, which is a good thing, since it is good UI design to label your buttons with the action that will happen when you click them. There is however no easy way to specify the default button of such a dialog, which is bad. Consider this confirmation dialog: Alert alert = new Alert(AlertType.CONFIRMATION); alert.setTitle("Really"); alert.setHeaderText("Danger, Will Robinson"); alert.setContentText("This will make the universe collapse. Are you sure?"); ButtonType yes = new ButtonType("Collapse", ButtonData.OTHER); ButtonType no = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE); alert.getButtonTypes().setAll(no, yes); alert.showAndWait(); It will make the "Collapse" option the default one, which is bad. I would expect sth. along the lines of alert.setDefaultButtonType(no) but no such API exists. Instead there are (AFAIK) two ways to work around this: 1) using DialogPane.lookupButton to lookup each button and calling setDefaultButton(true/false); this seems clumsy to me and also there is no guarantee for this to work (i.e. Alert could call setDefaultButton itself during showAndWait(), overriding what has been done before) 2) using ButtonData values that will produce the desired effect, e.g. ButtonType no = new ButtonType("Cancel", ButtonData.OK_DONE); but this is semantically wrong, the Cancel button is not really an OK_DONE button. Would it make sense to add an API (like alert.setDefaultButtonType(...))? Best regards, Robert From dlemmermann at gmail.com Tue Oct 20 13:57:14 2020 From: dlemmermann at gmail.com (Dirk Lemmermann) Date: Tue, 20 Oct 2020 15:57:14 +0200 Subject: JFX Days 2020 Message-ID: <09AAB383-C8A2-4327-821F-2848605E856B@gmail.com> Hi everyone, we will be having another installment of the JFX Days on November 24th / 25th. This year it will obviously be an online edition. If you would like to attend, then please register here (it?s free): jfx-days.com Dirk From daniel.peintner at gmail.com Tue Oct 20 14:33:59 2020 From: daniel.peintner at gmail.com (Daniel Peintner) Date: Tue, 20 Oct 2020 16:33:59 +0200 Subject: Default Buttons in Alert API In-Reply-To: References: Message-ID: Hi Robert, all, Providing an *easy* way to specify the default button in dialogs seems like a reasonable enhancement to me. Best, -- Daniel On Tue, Oct 20, 2020 at 10:26 AM Robert Lichtenberger < r.lichtenberger at gmail.com> wrote: > The Alert API allows to specify Button text, which is a good thing, since > it is good UI design to label your buttons with the action that will happen > when you click them. > There is however no easy way to specify the default button of such a > dialog, which is bad. > > Consider this confirmation dialog: > Alert alert = new Alert(AlertType.CONFIRMATION); > alert.setTitle("Really"); > alert.setHeaderText("Danger, Will Robinson"); > alert.setContentText("This will make the universe collapse. Are you > sure?"); > ButtonType yes = new ButtonType("Collapse", ButtonData.OTHER); > ButtonType no = new ButtonType("Cancel", ButtonData.CANCEL_CLOSE); > alert.getButtonTypes().setAll(no, yes); > alert.showAndWait(); > It will make the "Collapse" option the default one, which is bad. > I would expect sth. along the lines of alert.setDefaultButtonType(no) but > no such API exists. > Instead there are (AFAIK) two ways to work around this: > 1) using DialogPane.lookupButton to lookup each button and calling > setDefaultButton(true/false); this seems clumsy to me and also there is no > guarantee for this to work (i.e. Alert could call setDefaultButton itself > during showAndWait(), overriding what has been done before) > 2) using ButtonData values that will produce the desired effect, e.g. > ButtonType no = new ButtonType("Cancel", ButtonData.OK_DONE); > but this is semantically wrong, the Cancel button is not really an OK_DONE > button. > > Would it make sense to add an API (like alert.setDefaultButtonType(...))? > > Best regards, > Robert >