Save RTF File
Hi everyone,
I was thinking about saving RTF Files.
But what is wrong?
It just saves a blank RTF text document.
It wipes the text in the rich text box
Thanks,
klctal
I was thinking about saving RTF Files.
But what is wrong?
|
|
Source code |
1 2 3 4 5 6 7 8 9 |
Public Sub SaveRTF(RTB As RichTextBox,RTFFile As String) Dim Fil As New FileOutputStream Dim Doc As New DefaultStyledDocument(New StyleContext) Dim Kit As New RTFEditorKit Fil=New FileOutputStream(RTFFile) RTB.Parent.setEditorKit(Kit) RTB.Parent.setDocument(Doc) Kit.Write(Fil,Doc,0,0) End Sub |
It just saves a blank RTF text document.
It wipes the text in the rich text box
Thanks,
klctal
This post has been edited 2 times, last edit by "klctal" (Jul 23rd 2009, 10:46am)
Hi,
my suggestion:
You might want to add an "option explicit" as first line of your code to help detecting/preventing errors.
Cheers!
A1880
my suggestion:
|
|
Source code |
1 2 3 4 5 6 7 8 9 |
Public Sub SaveRTF(RTB As RichTextBox, RTFFileName As String) Dim fos As New FileOutputStream(New File(RTFFileName)) Dim Doc As Document = RTB.Parent.getDocument Dim kit As EditorKit = RTB.Parent.getEditorKit Call kit.Write(fos, Doc, 0,0) fos.close End Sub |
You might want to add an "option explicit" as first line of your code to help detecting/preventing errors.
Cheers!
A1880
Hi A1880,
I have tried your source code but there was some bugs. I changed it into this:
Now there was no bugs
but it only would show the common dialog(as I added) a lot of times.
I think it doesn't know the file name (RTFFileName)
Thanks,
klctal
I have tried your source code but there was some bugs. I changed it into this:
|
|
Source code |
1 2 3 4 5 6 7 8 9 10 |
Public Sub SaveRTF(RTB As RichTextBox, RTFFileName As String) Dim fos As New FileOutputStream fos=New FileOutPutStream(RTFFileName) Dim Doc As Document Doc=RTB.Parent.getDocument Dim kit As EditorKit kit = RTB.Parent.getEditorKit Call kit.Write(fos, Doc, 0,0) fos.close End Sub |
Now there was no bugs
but it only would show the common dialog(as I added) a lot of times.
I think it doesn't know the file name (RTFFileName)
Thanks,
klctal
Hi A1880,
There still is a bug on my computer!
The box at the down right corner (in red) says this:
Listening for transport dt_shmem at address: Jabaco33119813x165
Exception in thread "AWT-EventQueue-1" java.lang.InstantiationError: javax.swing.text.EditorKit
at Form1.SaveRTF(Form1.jsrc:220)
at Form1.Command1_Click(Form1.jsrc:22)
at Form1$CommandButton._Click(Form1.jsrc:285)
at VB.CommandButton.actionPerformed(CommandButton.jsrc:96)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at VBA.JabacoEventQueque.dispatchEvent(JabacoEventQueque.java:20)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
It's a little weird.
Thanks,
klctal
There still is a bug on my computer!
The box at the down right corner (in red) says this:
Listening for transport dt_shmem at address: Jabaco33119813x165
Exception in thread "AWT-EventQueue-1" java.lang.InstantiationError: javax.swing.text.EditorKit
at Form1.SaveRTF(Form1.jsrc:220)
at Form1.Command1_Click(Form1.jsrc:22)
at Form1$CommandButton._Click(Form1.jsrc:285)
at VB.CommandButton.actionPerformed(CommandButton.jsrc:96)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.AWTEventMulticaster.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Window.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.EventQueue.dispatchEvent(Unknown Source)
at VBA.JabacoEventQueque.dispatchEvent(JabacoEventQueque.java:20)
at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)
It's a little weird.
Thanks,
klctal
Hi,
if you "save" your RichTextBox before it has an EditorKit attached to ist, this exception can happen.
Please consult the LoadRTF() code how to attach a proper RTFEditorKit.
If you "load" before you "save", everything should be OK.
I am no expert in Java Swing. If I look at the Swing samples around the Internet, I'd rather leave it that way!
It could be one of the big merits of Jabaco to hide away the Swing secrets from ordinary developers.
Cheers!
A1880
if you "save" your RichTextBox before it has an EditorKit attached to ist, this exception can happen.
Please consult the LoadRTF() code how to attach a proper RTFEditorKit.
If you "load" before you "save", everything should be OK.
I am no expert in Java Swing. If I look at the Swing samples around the Internet, I'd rather leave it that way!
It could be one of the big merits of Jabaco to hide away the Swing secrets from ordinary developers.
Cheers!
A1880
Similar threads
-
General topics, questions and discussions »-
Trying New Version
(Jul 1st 2009, 12:09am)
-
General topics, questions and discussions »-
where is the jar-file?
(Jan 24th 2009, 1:49pm)
-
General topics, questions and discussions »-
PictureX.Line... How to do it in Jabaco?
(Jan 10th 2009, 6:01pm)
-
Suggestions »-
Make <ctrl>+s to save project
(Jan 12th 2009, 7:03pm)
