简体   繁体   中英

How can I set focus on text instead of button in SWT MessageDialog or MessageBox?

I am currently developing a program for blind people. In my program, I have several dialogs which are implemented using SWT MessageDialog or MessageBox .

This works just fine for sighted people or blind people who use screen reading software. But blind people who use refreshable braille display (which is text only and has just one line of 40 characters) have problem reading text message in the dialog because the focus of the dialog is on the button, so the refreshable braille display shows the text of the button. The blind people have to scroll up to find the text message.

Sometimes the scrolling is so hard that they have to complain about that. It would be nicer if the focus is on the text message, and then they can scroll down during reading the text, and at then end is the button text.

How can I use SWT MessageDialog or MessageBox class to manage the focus to be at the text message?

I don't want to create my own MessageDialog class because I use several options of the SWT libraries already.

Except for the 'Message' part in their name, MessageBox and MessageDialog are fundamentally different.

MessageBox is part of SWT and uses the component of the native platform to show the dialog and thus its behavior cannot be changed by application code.

The MessageDialog is provided by JFace and can be customized. If you really need to change the default focus behavior, you should use MessageDialog only.

To give focus to the label showing the message, you may override create() like this:

class MyMessageDialog extends MessageDialog {
  @Override
  public void create() {
    super.create();
    if( usingBraille ) {
      messageLabel.forceFocus();
    }
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM