The eclipse jface dialog box displays Chinese characters (a prompt box is displayed)

Source: Internet
Author: User

In jface, the dialog box is encapsulated through the shell window in SWT, and the button control object in SWT is called to viewSource codeIt can be found that the text of the set button is set by a character constant. The default value is English. To display a Chinese prompt, you must add a Chinese Language Pack.
In eclipse from entry to entry (version 2), it is described in eclipse 3.2.1. However, from the eclipse official website, it seems that the Language Pack only supports 3.2, and it will not be updated in the future. Fortunately, I don't need to define the entire eclipse. Now I need to display Chinese prompts IN THE jface dialog box.

I. Source Code
Take inputdialog as an example:

Inputdialog dialog = New Inputdialog (shell, "title", "enter a value", "1 ", Null );
If (Dialog. open () = inputdialog. OK ){
& Nbsp; string valuestr = dialog. getvalue ();
& Nbsp; messagedialog. openinformation (shell, "title", "input value:" + valuestr );
} Else // click the event button
Boolean call = messagedialog. openconfirm (display. getcurrent (). getactiveshell (), "OK", "Do you want to exit without warranty? ");
If (CALL) {// exit
System. Exit (0 );
}

Ii. default status
The default value is English:

3. Add a Chinese package
1. Download

Although the multi-language version is not available in eclipse 3.2, fortunately, for RCPProgramThis language pack is still useful.
To: Click
The Chinese package is in nlpack1. For rcpprogram, you only need to download nlpack1-eclipse-rcp-3.2-win32.zip.
After the download, extract the org. Eclipse. jface. nl1_3.2.0.v200606220026.jar file from the compressed package and put it in the project directory.

2. Set library reference for the project
Open eclipse, right-click the project name, select "properties", and click the "Libraries" tab under "Java build path:
Use "add jars..." to add the above libraries to the project directory. The result is as follows:

:

 

Others:

 

16.1 jface dialog box Overview
◆ Errordialog: displays error information based on the error level, which is generally used in the eclipse workbench.
◆ Messagedialog: displays the prompt dialog box, similar to the SWT dialog box, but it is more powerful than the SWT.
◆ Messagedialogwithtoggle: a message indicating whether to save the value set by the preference is displayed.
◆ Progressmonitordialog: displays the background thread progress dialog box.
◆ Inputdialog: enter information dialog box. You can also verify user input and display the verification information in the dialog box.
◆ Preferencedialog: a dialog box used to set preferences.
◆ Titleareadialog: a dialog box with the title, icon, and description information.
◆ Wizarddialog: Wizard dialog box.

16.2 message prompt dialog box (messagedialog)
Various types of information prompt dialog box examples:

/**  
* <P> class function description </P>
* Class description and other comments
*
* @ Author Jif liaojifeng@163.com
* @ Version V1.0
* @ Timer 2011-10-18 10:23:30 AM
*----------------------------------------------------------------------------
* Copyright (c) 2011
* Company *----------------------------------------------------------------------------
*/
Package Cn.net. comsys. window;

Import Org. Eclipse. jface. Action. statuslinemanager;
Import Org. Eclipse. jface. dialogs. messagedialog;
Import Org. Eclipse. jface. Resource. imagedescriptor;
Import Org. Eclipse. jface. Window. applicationwindow;
Import Org. Eclipse. SWT. SWT;
Import Org. Eclipse. SWT. Events. paintevent;
Import Org. Eclipse. SWT. Events. paintlistener;
Import Org. Eclipse. SWT. Events. selectionadapter;
Import Org. Eclipse. SWT. Events. selectionevent;
Import Org. Eclipse. SWT. Graphics. image;
Import Org. Eclipse. SWT. Graphics. Point;
Import Org. Eclipse. SWT. layout. griddata;
Import Org. Eclipse. SWT. layout. gridlayout;
Import Org. Eclipse. SWT. Widgets. composite;
Import Org. Eclipse. SWT. Widgets. Control;
Import Org. Eclipse. SWT. Widgets. display;
Import Org. Eclipse. SWT. Widgets. shell;
Import Org. Eclipse. SWT. Widgets. label;
Import Org. Eclipse. SWT. Widgets. text;
Import Org. Eclipse. SWT. browser. browser;
Import Org. Eclipse. SWT. Widgets. Button;
Import Org. Eclipse. SWT. Widgets. Canvas;
Import Org. Eclipse. SWT. Events. mouseadapter;
Import Org. Eclipse. SWT. Events. mouseevent;

Public ClassMessagedialogtestExtendsApplicationwindow {
PublicMessagedialogtest (){
Super(Null);
}

Protected VoidConfigureshell (shell ){
Super. Configureshell (Shell );
Shell. setsize (550,300 );
Shell. settext ("message dialog box example ");
}

Protected Control createcontents (composite parent ){
// The area in the window uses a text box as the message output and several buttons to open different dialog boxes respectively.
Composite composite = New Composite (parent, SWT. None );
Gridlayout = New Gridlayout (6, False );
Composite. setlayout (gridlayout );
Final Text console = New Text (composite, SWT. None | SWT. read_only | SWT. v_scroll );
Griddata DATA = New Griddata (griddata. fill_both );
Data. horizontalspan = 6;
Console. setlayoutdata (data );
Button openerror = New Button (composite, SWT. None );
Openerror. settext ("error message dialog box ");
Openerror. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Messagedialog. openerror (display. getcurrent (). getactiveshell (), "error message dialog box", "An error occurred while reading the file! ");
Console. append ("\ n openerror dialog box, return void ");
}
});
Button openconfirm = New Button (composite, SWT. None );
Openconfirm. settext ("Confirmation message dialog box ");
Openconfirm. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Boolean B = messagedialog. openconfirm (display. getcurrent (). getactiveshell (),
"Confirmation message dialog box ",
"Are you sure you want to save the file? ");
Console. append ("\ n openconfirm dialog box, return" + B );
}
});
Button openinformation = New Button (composite, SWT. None );
Openinformation. settext ("message dialog box ");
Openinformation. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Messagedialog. openinformation (display. getcurrent (). getactiveshell (), "message dialog box", "Are you sure you want to save the file? ");
Console. append ("\ n openinformation dialog box, return void ");
}
});
Button openquestion = New Button (composite, SWT. None );
Openquestion. settext ("Inquiry dialog box ");
Openquestion. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Boolean B = messagedialog. openquestion (display. getcurrent (). getactiveshell (), "query dialog box", "Are you sure you want to save the file! ");
Console. append ("\ n openquestion dialog box, return" + B );
}
});
Button openwarning = New Button (composite, SWT. None );
Openwarning. settext ("warning dialog box ");
Openwarning. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Messagedialog. openwarning (display. getcurrent (). getactiveshell (), "warning dialog box", "Are you sure you want to save the file! ");
Console. append ("\ n openwarning dialog box, return void ");
}
});
Button custommessagedig = New Button (composite, SWT. None );
Custommessagedig. settext ("Custom dialog box ");
Custommessagedig. addselectionlistener ( New Selectionadapter (){
Public Void Widgetselected (selectionevent e ){
Messagedialog dialog = New Messagedialog (display. getcurrent (). getactiveshell (), // Shell window
"This is the title of the dialog box ", // Title
Null , // The icon in the dialog box. If it is null, no icon is displayed.
"This is a custom dialog box. You can change the button settings ", // Prompt information in the dialog box
Messagedialog. Information, // Prompt icon
New String [] {"View", "save", "OK "}, // Show three buttons
1 ); // The index value of the default button, which is 1, indicates that the second button is selected by default, that is, the Save button.
Int I = dialog. open (); // Return Value: button
Console. append ("\ n custom dialog box, return the index value of the button" + I );
}
});
Return Parent;
}
Public Static Void Main (string [] ARGs ){
Messagedialogtest test = New Messagedialogtest ();
Test. setblockonopen ( True );
Test. open ();
Display. getcurrent (). Dispose ();
}

}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.