Due to the inherent defect of swing, jeditpane has weak functions. If you want to use word, you have to use Jacob, and you can only control the control without editing controls.
SWT is much better, word, ie want to use what direct tune on the line, it seems that more attention to SWT in the future.
Package gui. test;
Import java. Io. file;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. layout. filllayout;
Import org. Eclipse. SWT. Ole. win32.oleclientsite;
Import org. Eclipse. SWT. Ole. win32.oleframe;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. shell;
Public class wordview extends org. Eclipse. SWT. Widgets. Composite {
Private oleframe oleframe1;
Private oleclientsite site;
/**
* Auto-generated main method to display this
* Org. Eclipse. SWT. Widgets. Composite inside a new shell.
*/
Public static void main (string [] ARGs ){
Showgui ();
}
/**
* Auto-generated method to display this
* Org. Eclipse. SWT. Widgets. Composite inside a new shell.
*/
Public static void showgui (){
Display display = display. getdefault ();
Shell shell = new shell (Display );
Shell. settext ("word in SWT ");
New wordview (shell, SWT. null );
Shell. setlayout (New filllayout ());
Shell. layout ();
Shell. setsize (600,400 );
Shell. open ();
While (! Shell. isdisposed ()){
If (! Display. readanddispatch ())
Display. Sleep ();
}
}
Public wordview (Org. Eclipse. SWT. Widgets. Composite parent, int style ){
Super (parent, style );
Initgui ();
}
Private void initgui (){
Try {
Filllayout thislayout = new filllayout (
Org. Eclipse. SWT. SWT. Horizontal );
This. setlayout (thislayout );
This. setsize (229, 54 );
{
Oleframe1 = new oleframe (this, SWT. None );
{
Try {
Site = new org. Eclipse. SWT. Ole. win32.oleclientsite (oleframe1, org. Eclipse. SWT. SWT. None, "word. Document ");
Site. setbounds (0, 0,104, 54 );
Site. doverb (Org. Eclipse. SWT. Ole. win32.ole. oleiverb_show );
} Catch (Org. Eclipse. SWT. swtexception e ){
String STR = "create oleclientsite error" + E. tostring ();
System. Out. println (STR );
Return;
}
}
}
This. layout ();
} Catch (exception e ){
E. printstacktrace ();
}
}
Private void open (File file ){
Site = NULL;
Try {
Site = new org. Eclipse. SWT. Ole. win32.oleclientsite (oleframe1, org. Eclipse. SWT. SWT. None, file );
Site. setbounds (0, 0,104, 54 );
Site. doverb (Org. Eclipse. SWT. Ole. win32.ole. oleiverb_show );
} Catch (Org. Eclipse. SWT. swtexception e ){
String STR = "create oleclientsite error" + E. tostring ();
System. Out. println (STR );
Return;
}
}
Public void open (string strname ){
// Site. (new file (strname), true );
Open (new file (strname ));
}
Public void save (string strname ){
Site. Save (new file (strname), true );
}
}
Package gui. test;
Import org. Eclipse. SWT. SWT;
Import org. Eclipse. SWT. Events. selectionadapter;
Import org. Eclipse. SWT. Events. selectionevent;
Import org. Eclipse. SWT. Widgets. Button;
Import org. Eclipse. SWT. Widgets. display;
Import org. Eclipse. SWT. Widgets. filedialog;
Import org. Eclipse. SWT. Widgets. shell;
Public class swtdemo {
/**
* Launch the application
* @ Param ARGs
*/
Public static void main (string [] ARGs ){
Final display = display. getdefault ();
Final shell = new shell ();
Shell. setsize (500,375 );
Shell. settext ("SWT application ");
//
Final wordview composite = new wordview (shell, SWT. null );
Composite. setbounds (0, 0,490,295 );
Final button open = new button (shell, SWT. None );
Open. settext ("Open Document ");
Open. setbounds (315,310, 70, 20 );
Final button save = new button (shell, SWT. None );
Save. setbounds (412,310, 70, 20 );
Save. settext ("Save document ");
Shell. layout ();
Open. addselectionlistener (New selectionadapter (){
Public void widgetselected (selectionevent event ){
Filedialog DLG = new filedialog (shell, SWT. Open );
DLG. setfilternames (New String [] {"Word Document (*. Doc )"});
DLG. setfilterextensions (New String [] {"*. Doc "});
String filename = DLG. open ();
If (filename! = NULL ){
Composite. Open (filename );
}
}
});
Save. addselectionlistener (New selectionadapter (){
Public void widgetselected (selectionevent event ){
Filedialog DLG = new filedialog (shell, SWT. Save );
DLG. setfilternames (New String [] {"Word Document (*. Doc )"});
DLG. setfilterextensions (New String [] {"*. Doc "});
String filename = DLG. open ();
If (filename! = NULL ){
Composite. Save (filename );
}
}
});
Shell. open ();
While (! Shell. isdisposed ()){
If (! Display. readanddispatch ())
Display. Sleep ();
}
}
}
In other words, paste my Testing Program (for beginners, SWT, designer interfaces, the core code is copied online ).
To be honest, I think the SWT implementation method is really not as comfortable as swing. Don't laugh at me.
There is also oleview under vs2003. Do you know anyone?