More JTextPane Questions

Hi Guys
I posted this question on the Java Ranch forums yesterday evening, but I haven't received a response yet, so I figured that I'd try these forums as well. You can view the other thread here;
We're trying to build a simple WYSIWYG HTML editor using a JTextPane. I've used Charles Bell's example, available here; as a reference. My biggest gripe with it at the moment is that bullets aren't working as I would expect them to. If I highlight text and click the "Bullet" button, I want a bullet to be placed immediately before the highlighted text, on the same line. If I try to do this, my code is creating bullets, but it moves the selected text one line down. I've gone through the Oracle tutorial on text components, but I couldn't find anything that helped me with this particular issue.
Also, if I copy and paste text into my JTextPane, the pasted text always appears on a new line (a new paragraph tag in the actual HTML). Is there a way to prevent the JTextPane from creating new paragraphs?
Lastly, I'm flabbergasted as to why my buttons actually work. I can't see anything that explicitly links my buttons to my HTMLEditorKit or my JTextPane. Short of a little voodoo man living under my keyboard, how on earth do my buttons/actions know that they should update the JTextPane?
The code is as follows;
package myhtmleditor;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.Action;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextPane;
import javax.swing.SwingUtilities;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
public class Main {
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            public void run() {
                JFrame frame = new JFrame("My HTML Editor");
                frame.setSize(500, 500);
                frame.setLayout(new BorderLayout());
                JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
                HTMLDocument document = new HTMLDocument();
                final JTextPane htmlEditorPane = new JTextPane(document);
                Action bold = new StyledEditorKit.BoldAction();
                Action italic = new StyledEditorKit.ItalicAction();
                Action underline = new StyledEditorKit.UnderlineAction();
                JButton boldButton = new JButton(bold);
                JButton italicButton = new JButton(italic);
                JButton underlineButton = new JButton(underline);
                HTMLEditorKit.InsertHTMLTextAction bulletAction = new HTMLEditorKit.InsertHTMLTextAction("Bullet", "<ul><li> </li></ul>", HTML.Tag.BODY, HTML.Tag.UL);
                JButton bulletButton = new JButton(bulletAction);
                JButton printButton = new JButton("Print to Console");
                printButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                HTMLEditorKit editorKit = new HTMLEditorKit();
                frame.add(buttonsPanel, BorderLayout.NORTH);
                frame.add(new JScrollPane(htmlEditorPane), BorderLayout.CENTER);
}Thank you for your input.

See how the bullet action changes HTML (compare getText() result before and after the bullet applying. It seems you need more smart way of adding bullets.
Answer some questions if user selects whole paragraph should the <p> tag be removed and replaced with <li>? If user selects just one word in the paragraph and pressed bullet should the whole paragraph be bulleted?
When you copy something you clipboard contains something like this "<html><body> content</body></html>". Try to override read() method of your kit (or Reader) to skip the main tags.
For components see ObjectView class source.
In fact when HTMLDocument is created from String components classes are created and stored in attributes of Elements. Then during rendering ComponentView extension (ObjectView) creates components.

Similar Messages

  • I need some more interview question with answer on modeling,reporting.

    i need some more interview question with answer on modeling,reporting.

    You may find tons of topic about interview question. Please try to search forums before opening a post next time.Take a look at the link below.

  • Every time I try to get on the ipod, it says I have to add more security questions, but none are listed, just two buttons that say submit.

    Every time I try to get on the Ipod games, it says I have to add more security questions, but no questions are listed, just two buttons that say "Submit" and places to put the answers to the unstated questions.  It also asks for a second email address.  It then proceeds to lock up.  Is this a scam of some sort.  There is nothing on the apple website about having additional security questions other than the one, or having a second email to operate the ipod.

    You need to contact Apple to get the questions reset. Click here, phone them, and ask for the Account Security team, or fill out and submit this form.
    Whichever method you use, you probably won't get a response until the 26th. If you absolutely must make a purchase before then, create a new Apple ID; you won't be able to transfer previous purchases or iTunes Store credit to it.

  • A Simpler, More Direct Question About Merge Joins

    This thread is related to Merge Joins Should Be Faster and Merge Join but asks a simpler, more direct question:
    Why does merge sort join choose to sort data that is already sorted? Here are some Explain query plans to illustrate my point.
      2  SELECT * FROM spoTriples ORDER BY s;
    |   0 | SELECT STATEMENT |              |   998K|    35M|  5311   (1)| 00:01:04|
    |   1 |  INDEX FULL SCAN | PKSPOTRIPLES |   998K|    35M|  5311   (1)| 00:01:04|
    ---------------------------------------------------------------------------------Notice that the plan does not involve a SORT operation. This is because spoTriples is an Index-Organized Table on the primary key index of (s,p,o), which contains all of the columns in the table. This means the table is already sorted on s, which is the column in the ORDER BY clause. The optimizer is taking advantage of the fact that the table is already sorted, which it should.
    Now look at this plan:
      2  SELECT /*+ USE_MERGE(t1 t2) */ t1.s, t2.s
      3  FROM spoTriples t1, spoTriples t2
      4  WHERE t1.s = t2.s;
    |   0 | SELECT STATEMENT       |              |    11M|   297M|       | 13019 (6)| 00:02:37 |
    |   1 |  MERGE JOIN            |              |    11M|   297M|       | 13019 (6)| 00:02:37 |
    |   2 |   SORT JOIN            |              |   998K|    12M|    38M|  6389 (4)| 00:01:17 |
    |   3 |    INDEX FAST FULL SCAN| PKSPOTRIPLES |   998K|    12M|       |  1460 (3)| 00:00:18 |
    |*  4 |   SORT JOIN            |              |   998K|    12M|    38M|  6389 (4)| 00:01:17 |
    |   5 |    INDEX FAST FULL SCAN| PKSPOTRIPLES |   998K|    12M|       |  1460 (3)| 00:00:18 |
    Predicate Information (identified by operation id):
       4 - access("T1"."S"="T2"."S")
           filter("T1"."S"="T2"."S")I'm doing a self join on the column by which the table is sorted. I'm using a hint to force a merge join, but despite the data already being sorted, the optimizer insists on sorting each instance of spoTriples before doing the merge join. The sort should be unnecessary for the same reason that it is unnecessary in the case with the ORDER BY above.
    Is there anyway to make Oracle be aware of and take advantage of the fact that it doesn't have to sort this data before merge joining it?

    Licensing questions are best addressed by visiting the Oracle store, or contacting a salesrep in your area
    But I doubt you can redistribute the product if you aren't licensed yourself.
    Question 3 and 4 have obvious answers
    3: Even if you could this is illegal
    4: if tnsping is not included in the client, tnsping is not included in the client, and there will be no replacement.
    Tnsping only establishes whether a listener is running and shouldn't be called from an application
    Sybrand Bakker
    Senior Oracle DBA

  • A few more Solaris questions

    I'm sure this isn't the best place to post this, but I currently have a file server running Solaris 11 with a raid-z2 pool and I'm building a new vmware server out of some parts I've managed to get some good deals on might I add.
    I'm building on a supermicro x8dt3-f board that has an LSI controller on board with a pair of xeon 5570's and 48gb ram. The processors and ram actually came from a sun blade that was tossed out for recycling, sadly the box had never been opened, but i got these for pennies on the dollar, so i'm happy
    I'd like to move the current Solaris file server into a VM on the new ESXi 5.1 host and passthrough the LSI controller.
    I've been reading, and reading and reading and i find the more i read, the more questions I have and the less clear some of the answers are getting.
    First, from what I gather, Solaris 11 has only been added to the supported guest list in ESXi with the recent esxi 5.1 version as I understand? So all should be fine here? Can someone confirm?
    second, i've read about issues with LSI controllers under solaris 11. Is this something that has been addressed in 11.1?
    Third, trying to find the best method to conver the physical system to virtual under ESXi
    The first thing I plan on doing is backing up my data from the pool, though it will be scattered across a few systems. Then I plan on exporting the pool to move the disks physically to the new controller in the VM. The question I have here, is will the share flags and permissions be retained when I import the pool? or do I have to redo all that?
    But then, what's the best method to move it to a VM? The one document I see come up the most is moving a physical solaris system into a zone on another system. Can it be transferred to the global zone? Could I do a new install in a VM, and move the existing install to the global zone, import my pool and call it a daY?
    Or do I dd the OS disk, convert the image and drop it into vmware, get the hardware working, and then import the pool?
    Or is there a better way? Has anyone got any online docs in mind that may help specifically with this migration? everything i'm finding is scattered, maybe i'm not looking for the right things but I could use some pointers if anyone has suggestions.
    I suppose I should note, i have it integrated with an Active directory, this is why i'm worried about permissions being retained when i import the pool
    I just want this to go as quickly and smoothly as possible, with as little headache as possible. it's my home setup, so realistically it takes the time it takes as long as things go smooth

    I know this may not be the answer you are looking for, but I think you are making it more difficult than it needs to be.
    One other option is to leave your Solaris Storage server on the bare metal of this new beast of a machine you are piecing together. Then, use VirtualBox 4.2.6 which is support quite well in Solaris to run whatever virtual machines you where intending ESXi to be used for.
    This way you have the fastest possible storage setup without the issues of hardware passthrough. And the fast storage now benefits the VMs running on it. Not to mention the other neat options now of running lzjb compression for the VMs. either using zvols for the VMs, or just virtualbox vdi files sitting on a compressed zfs filesystem.
    As far as the LSI 1068E controller goes, their website only shows drivers for Solaris 10. So unless Solaris 11 has the drivers built in, you may not be able to use that controller. Believe me I feel your pain in this one.. I have the d#$$!est time finding good SAS HBAs for Solaris 11.1 and the few I did find had questionable drivers. Areca 1320 cards seem to work well, as do Adaptec 64xx and 68xx raid cards. LSI has a new line that supposedly works with Solaris 11.
    My advice is to try a baremetal install of Solaris 11.1 on the new machine and see if you can recognize drives on the LSI controller, if not then use the 6 onboard SATA ports if that is enough for the drives. Otherwise purchase an Areca 1320 which is only like 230 bucks for the 8 port version.

  • I'm trying to purchase but buy results in "add 3 more security questions"

    After Press buy, message is add three security questions. But when i goto and manage my account, it has one security question and i don't see where to add more.
    Or why 3 in addition to the one I see already within my account?
    Thank you!

    Welcome to the Apple Community.
    Have you tried repurchasing again after amending your security at my Apple ID.

  • More XControl questions / issues

    XControl 1, X1, has two other XControls, X2 and X3, on its
    block diagram
    When I open a VI with X1 on it, the Init ability is called
    for X2 and X3 three times each.  X1’s
    Init ability is called one time.  (The
    other VIs you see pop up are called from X2 and X3 as a result of Init
    executing, so they illustrate the Init calls. 
    They close when Uninit is called, and you can see as much when you close
    the VI and project)
    When I close said VI, the Uninit ability is called for X1
    and called twice for X2 and X3.  This, of
    course, leaves one instance of X2 and X3 left open.  Consequently, references and VI’s I opened as
    a result of the Init call are left open (you notice the two subvi's still open). 
    Once I close the project, the Uninit abilities are called
    for X2 and X3, closing the remaining resources.
    There is a file in the folder called log.txt I write to in
    the init and Uninit abilities for each XControl.  If you open it after each step you can see
    what I’m talking about.
    Additional things: 
    After I close the VI, but not the project, X2 and X3 are of course
    locked.  When I right click “Unlock this
    library for Editing”, LabVIEW crashes with a .cpp error.
    My real project loads the XControls (and executes the Init ability) as soon as it opens for
    some reason, and makes it nearly impossible to edit them unless I close and open the
    XControls individually, due to the .cpp error above.
    Is it expected that an XControl an another XControl should be called more than once?
    Why don't they get unloaded when the main XControl is closed and unloaded?
    Why the .cpp error?
    Tim Elsey
    LabVIEW 2010, 2012
    Certified LabVIEW Architect
    XControl Forum Test ‏165 KB
    XControl demo ‏3598 KB

    Hello elset191
    Here is the Corrective Action Request that references your issue.  I have included you as a customer whom this problem is affecting.
    Request #: 302463
    Description: XControls remain open after corresponding VI is closed and crash occurs, XControl cpp error in LabVIEW 8.6.1f1 (Fatal Internal Error: "ThEvent.cpp", line 184) 
    I'm sorry that this has been a frustration to you.  The fastest way to resolve this issue appears to upgrade.  Have you attempted to reproduce this error in LabVIEW 2010 SP1?  I was unable to reproduce this situation in LabVIEW 2010 SP1.
    The CPP error is due to some issue with how this has been internally developed.  It appears to have been resolved in LabVIEW 2010 SP1 as do the other issues you have been dealing with.  Can you please confirm this for me?  I am happy to further address this issue to ensure your success.  All the best!
    P.S.  I have provided a link to the LabVIEW 8.6 Help simply for competeness.
    Editing XControls that are in Use
    Greg S.

  • More clear question  for slideshow help - Kin?

    Hi Kin,
    You have been very helpful in getting me this far - I know
    this last detail would be a very easy thing for you to do.
    I tried to get it to work for the dssmTitle by adding another
    The mouseover function is fine the way it is. It's how it
    behaves during the slideshow that is a little wierd - it just sits
    on the first story. It would be great if it switched to each story
    like the small nav at the bottom highlights to each corresponding
    nav to its story during the slideshow.
    I hope this is more clear.

    Hi TS,
    So it sounds like you want to change the current row of
    dschapters and stop the slide show on mouesover, and then re-enable
    the slideshow on mouseout right?
    Try something like this:
    var gTimerID = 0;
    var gInterval = 3000;
    function StartSlideShow()
    gTimerID = setInterval(function(){
    dschapters.setCurrentRowNumber((dschapters.getCurrentRowNumber() +
    1) % dschapters.getRowCount()); }, gInterval);
    function StopSlideShow()
    if (gTimerID)
    gTimerID = 0;
    if (nt == "onPostLoad")
    <div id="nav" spry:detailregion="dschapters"
    spry:repeatchildren="dschapters" spry:choose="choose">
    <div spry:when="{ds_RowID} == {ds_CurrentRowID}"
    id="nav2" class="currentChapter" spry:setrow="dschapters"
    spry:hover="hoverRow"><img src="{thPhoto}"
    onmouseout="StartSlideShow();" /> </div>
    <div spry:default="default" id="nav2"
    spry:setrow="dschapters" spry:hover="hoverRow"><img
    src="{thPhoto}" onmouseover="StopSlideShow();
    onmouseout="StartSlideShow();" /></div>
    On a side note, if you are trying to bring your question to
    the top of the forum again, post a message in your original thread
    ... that is don't create a new thread each time ... that way the
    context of your questions is preserved for others to read. If you
    post new threads each time, folks have to search for your previous
    posts/threads to get context.
    --== Kin ==--

  • More font questions

    What I can't seem to find in any of these replies--I probably just haven't found the right one yet!--is whether the new OS X Tiger can use older mac fonts or any of the free mac fonts available on the internet...and that goes for all free mac downloads. I can't seem to get ANYTHING in a format that actually works with this OS!
    I have hundreds of great fonts on my older macs, but I'm guessing if they are not TTF (which most, of course, will not be) they won't transfer. Also, it seems that the vast majority of downloads come through as .sit files--not sure what that is, but they are not registering as fonts. Now what?

    Hi rosy,
    Welcome to the discussions and the AppleWorks forum.
    This is more an OS X question than an Appleworks one, and you may get a more definitive reply by pisting in the Tiger forum.
    ".sit" is a suffix that identifies a file compressed using Stuffit, the 'standard' compression application for Mac under OS 9 and earlier. To open these you need the free download of Stuffit Expander.
    If your older fonts are TrueType (which most of the scaleable ones will be) they should be useable in Tiger. Bit Map fonts (any that showed some sizes in black and others in outline in the Font menu on your older Mac) may not be useable in OS X.

  • More MOH Questions

    Hi Everyone
    I'm looking at the MOH options now and I have a question, I went to the MOH audio source and the MOH server configuration. And I see that each one has an option to allow multicasting, but in the server configuration they have base multi-cast IP and base mutli-cast port. I wanted to know is th IP and what would I put for the port.

    You have to put the valid multicast port numbers which include even numbers that range from 16384 to 32767.
    Here in your case the MoH server will be streaming a multicast audio source to on RTP port specified.
    Refer below link for MOH Configuration and more detail,

  • More Distortion Questions

    I posted about this before but now realize I may have misdiagnosed the problem.
    I have a DV quicktime file that play perfectly. When brought into FCE 3.5.1 however, there's one scene that becomes very distorted. Tom Wolsky originally suggested it was deinterlacing, but now that I've seen more examples of that I definitely don't think that is the issue.
    There's a scene where a person turns his face in front of the camera. As he does, these big splotches of distortion appear. If you ever look through an imperfect piece of glass, that would best describe it. It's not horizontal lines. Almost the way you'd see things bend a bit with a funhouse mirror.
    What could be causing this? The distortion only appears when the clip is brought into FCE. Then appears when I burn the exported movie onto a DVD via iDVD.
    Please help.

    Is this clip from the same source as the others?
    If it is, sounds really weird.
    At a wild guess, can you check to see that a filter has not been inadvertently added to the clip in question. Some filters can add that type of distortion effect.

  • More session questions

    Enumeration e = session.getAttributeNames(); String key, value;
    while( e.hasMoreElements() ) {
    key = (String) e.nextElement();
    value = (String) s.getAttribute( key );
    out.print( key + value );
    I'm not familiar with (String) usage, lines 3,4.
    It's obvious what's happening, though. My questions follow.
    1.) Why is the reserved word String in parentheses?
    2.) What other reserved words could I use in its place?
    3.) By deleting it, error says it found Object but required String.
    In earlier code, I defined it as a String. What gives?
    [email protected]

    the syntax (String) is called a CAST - it converts the 'type' of an object from one type to another.
    in this case it's converting from the type Object to type String - this is basic Object talk - read any beginning
    book on OO/Java and get a better understanding.
    one must cast the object returned from the enumeration to a more usefull type - but you may find
    that the code has run time errors - if the enumeration has other than Strings in it - for example
    one could put a Boolean object in the enumeration and casting to a String will give a class cast exception
    at run time.

  • More General Questions.

    Hi Guys,
    1. Is it better to "close" a production order or "technically complete" it after the production is complete? Will it make a difference?
    2. What dates are more important for tracking in a production order? Basic Dates or Actual Dates?
    3. I am planning on implementing cost center accounting to capture costs from the machine and labor times given in the routing. Is there any easier method?
    Thanks in advance for your help.
    Will give points.

    Dear Rao,
    1. Is it better to "close" a production order or "technically complete" it after the production is complete? Will it make a difference?
    It is not the question of which is better, they serve different purposes.
    TECO - The production order will not be relevant for MRP. Settlement can be done.
                Confimations and GR/GI of production order still possible.
    CLSD - The production order will not be relevant for MRP. If goods movements have taken place and / or activity booking done, then "closing" is <b>not possible</b> without settlement done. Confimations and GR/GI of production order <b>not possible</b>..
    2. What dates are more important for tracking in a production order? Basic Dates or Actual Dates?
    Both of the dates are important and have their roles to play.
    Basic dates are important for scheduling.
    Actual dates are important for leadtime scheduling and consequently capacity planning.
    3. I am planning on implementing cost center accounting to capture costs from the machine and labor times given in the routing. Is there any easier method?
    Your plan is nice and cool.
    Hope this will help you, please confirm.
    Angshuman Kar

  • More implementation questions

    We are continue to investigate our trial version in order to prepare an internal review. We successfully implemented few workflows but have some questions:
    1/ Is it correct that in order to put a stamp "Approved" for the dcument which has passed review process it is necessary to use Assembler task? If yes when where we can get more details about DDX? How to position out stamp inside document?
    2/ We have find some interesting option in Workspace client (see screenshot). Could you please clarify how it is used? We had tried to validate a document with one step and on next step of our workflow this tool did not show that document was approved previously. We checked this for  Multiuser or Single user task assignment. What did we miss?

    The DDX Reference is here:
    I believe chapter 9 in Part 1 is what you should see.
    To get that UI to appear in Workspace, you use the Approval Container option of the  Workspace User Interface property. See this
    The Status area displays the comments that users have provided for the task, as well as the User Action that they selected to complete the task. This is most commonly used with Assign Multiple Tasks operations, but can be used with Assign Task as well. The Status area simply displays information from the Task Result Collection that you are using to store task data. See this:
    hope that helps

  • More BB Questions

    well I might have bitten off more than I can chew. Business folders are now on the BB under my yahoo email account AND show up under the I ended up with over 500 emails on the Hub which makes managing it somewhat of a problem...................if I delete an email in the folder it deletes it on my main the question is if I delete the folder..........................and I need help figuring that out I do not want it deleted from the main computer..................any ideas? thanks for your help

    I would not delete a folder on the device. I would just disable the sync of it, so you will not get any emails from that folder on the device. To do that
    - Go to Blackberry Hub
    - Press the Menu key, choose "Settings"
    - Tap "Email Accounts"
    - Choose your Yahoo account
    - Tap on the little "Pencil" on the bottom of the screen
    - Go to "Edit Folder Settings"
    - Un-tick the folders that you don't want to see on your device
    - Tap on "Save" in the upper right corner
    That's it.
    Blackberry Engineering in Switzerland - Dexion Services AG

Maybe you are looking for

  • To update vendor and customer details in BP transaction

    I have created a donor in the BP transaction . i need to update the vendor and customer details for the reated donor. please can someone suggest some BAPI's or FM's which are available to do the same.

  • How do I get a hacker off of my laptop? PLEASE HELP!

    This person has changed my password on my gmail multiple times, yahoo account as well, and I'm sure he's gotten into other stuff. I don't know if it's from my desktop or phone or what? I set my laptop back to factory setting but he still changed my g

  • HT1414 cannot open my 3g iphone after the upgrade?

    i accidentally click on set to new after upgrading my iphone, now i can't open it , it's just stuck on recovery mode..

  • My Macbook Pro will not startup

    I am pretty sure I downloaded something bad for my macbook pro because it shut down on me and now upon rebooting, it will come to the login page, ask for my password. I enter it in and click enter, I get a partial black screen with a lot of text that

  • Duplex printing with a twist

    I have a document that I need to print duplexed, but the duplexing only is done when X happens.  For example, this document has to do with account balances for a specific project.  If the project doesn't fit on one page, I want to print the balance o