Line wraping only selected text in JTextPane

Is it possible to not word wrap styled text word groups in JTextPane so that the word groups are kept together. I would have liked to do this with by adding a 'keep together' attrib. to StyleConstants in my StyledDocument but sadly this is not possible. (unless anyone knows differently)
The only alternative I can think of is to insert "\n" before a word group when I detect a word group has been broken up, but this seem a messy solution.
Does anyone know a way of overriding the underlying wrapping code to keep a styled group together?
Many Thanks..Matt.

The solution I have arrived at is to insert translucent "_" characters to replace spaces in words I want to glue together. Not a good solution though.
//ent is the object representing the words to be glued
Pattern p = Pattern.compile("[ ]");
Matcher myMatcher = p.matcher(ent.getOccuranceText());
while (myMatcher.find()) {
          int startSpace = myMatcher.start();
          getStyledDocument().setCharacterAttributes(
          ent.getStart()+startSpace,
          1,
          getStyledDocument().getStyle(Article.INVISIBLE),
          false); //false as we want to preserve previous formating
}And to the style document I add
Style invisible = docIn.addStyle(Article.INVISIBLE, regular);
StyleConstants.setForeground(invisible,new Color(0, 0, 0, 0));

Similar Messages

  • How can i Change the Size of the selected text in JTextPane using ConboBox

    plzz help...
    How can i Change the Size of the selected text in JTextPane using ConboBox ???
    i m using if(cb.getSelectedItem=="small")
    cb.setAction(new StyledEditorKit.FontSizeAction("double click", 12);)
    if(cb.getSelectedItem=="medium")
    cb.setAction(new StyledEditorKit.FontSizeAction("double click", 14);)
    if(cb.getSelectedItem=="large")
    cb.setAction(new StyledEditorKit.FontSizeAction("double click", 16);)
    this code is not working properly according to the action i set on comboBox.
    when i select medium the previously set action on comboBox works like small action work.
    when i select large the medium action starts .
    means its not working in correct time when i select item of combox n action of that item is not working at that time..
    plzz plzz help me:(

    Action action1 = new StyledEditorKit.FontSizeAction(
    "double click", 12);
    Action action2 = new StyledEditorKit.FontSizeAction(
    "double click", 14);
    Action action3 = new StyledEditorKit.FontSizeAction(
    "double click", 18);
    s2 = (String) cb7.getSelectedItem();
    if (s2.equals("Small")) {
    cb7.setAction(action1);
    e1.setSource(cb7);
    } else
    if (s2.equals("Medium")) {
    cb7.setAction(action2);
    e1.setSource(cb7);
    } else if (s2.equals("Large")) {
    cb7.setAction(action3);
    // e1.setSource(cb7);
    when i chooze any combobox item then according to that item i set the Action on ComboBox but that action is not working properly on the selected text in the JTextPane..means selected text in JText Pane is not changes its Size according to the comboBox selected ITEM.
    PLZ plzzzzzzzzzz help me:((.i will be thankfull to u.

  • I can't print only selected text since upgrading to Firefox 8.0. Using Mac OS Lion

    Until Firefox 8.0, I could select text on any webpage and print only that text. Now, I can't even get a print dialog box with an option to "Print Selection" only.
    I also recently upgraded to OS Lion (from OS Leopard) on Mac. Any chance that that is the problem or is it in Firefox? I've seen lots of help requests on this site from other people with problems printing selected text from websites.

    Firefox hangs the same way in safe mode.
    There is no such thing as a Firefox program folder on a Mac, nor is there an "uninstall" to do, so these directions are not relevant to a Mac user.
    The problem remains.

  • ComboBox Problem to change the size of selected text in JTextPane.

    hi 2 all!
    I have a problem in combo box actions, when i change the item in the combo its set is not set at that time but that action is performed when next action is taken, i have used combobox.setAction(new StyledEditorKit.FontSizeAction(" click", 12);) command to set the size of the selected text
    Plz suggest the solution also if possible,plz provide some code for this
    Action action1 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 12);
                                       Action action2 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 14);
                                       Action action3 = new StyledEditorKit.FontSizeAction(
                                                 "double click", 18);
    s2 = (String) cb7.getSelectedItem();
                                       if (s2.equals("Small")) {
                                            cb7.setAction(action1);
                                            e1.setSource(cb7);
                                                      } else
                                       if (s2.equals("Medium")) {
                                            cb7.setAction(action2);
                                            e1.setSource(cb7);
                                                                          } else if (s2.equals("Large")) {
                                            cb7.setAction(action3);
                                            // e1.setSource(cb7);
    when i chooze any combobox item then according to that item i set the Action on ComboBox but that action is not working properly on the selected text in the JTextPane..means selected text in JText Pane is not changes its Size according to the comboBox selected ITEM.
    PLZ plzzzzzzzzzz help me:((.i will be thankfull to u.
    thanx in advance..

    this code is not working properly according to the action i set on comboBox.Thats correct, the setAction() method is used to invoke an existing Action on the combo box, not create a new Action.
    What you need to do is have a single action that uses the information from the item that was selected to build a dynamic Action to change the font. Something like:
    public void actionPerformed(ActionEvent e)
         JComboBox comboBox = (JComboBox)e.getSource();
         int fontSize = Integer.parseInt( comboBox.getSelectedItem().toString() );
         Action fontAction = new StyledEditorKit.FontSizeAction("size", fontSize);
         fontAction.actionPerformed(null);
    }

  • How to set selected text on JTextPane ?

    I need to set selected text on a JTextPane. I used setSelectionStart(); and setSelectionEnd(); but it doesn't work.
    Can anybody help me?

    I'm not sure if this is what you are looking for, but the following code sample was revised from the tutorial TextSamplerDemo.java. It will hightlight the word "selected" in yellow in the JTextPane.
    //created with j2sdk1.4.0_01
    import javax.swing.*;
    import javax.swing.text.*;
    import java.awt.*;
    import java.awt.event.*;      
    public class SelectedText extends JFrame {
        public SelectedText() {
            super("Selected Text");       
            //Create a text pane.
            JTextPane textPane = createTextPane();
            JScrollPane paneScrollPane = new JScrollPane(textPane);
            paneScrollPane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
            paneScrollPane.setPreferredSize(new Dimension(250, 155));
            paneScrollPane.setMinimumSize(new Dimension(10, 10));
            Container pane = getContentPane();
            pane.add(paneScrollPane);
        private JTextPane createTextPane() {
            JTextPane textPane = new JTextPane();
            String[] initString =
                    { "This is the ", //regular
                      "selected",     //selected
                      " text. "       //regular
            String[] initStyles = {"regular", "selected", "regular"};
            initStylesForTextPane(textPane);
            Document doc = textPane.getDocument();
            try {
                for (int i=0; i < initString.length; i++) {
                    doc.insertString(doc.getLength(), initString,
    textPane.getStyle(initStyles[i]));
    } catch (BadLocationException ble) {
    System.err.println("Couldn't insert initial text.");
    return textPane;
    protected void initStylesForTextPane(JTextPane textPane) {
    //Initialize some styles.
    Style def = StyleContext.getDefaultStyleContext().getStyle(StyleContext.DEFAULT_STYLE);
    Style regular = textPane.addStyle("regular", def);
    StyleConstants.setFontFamily(def, "SansSerif");
    Style s = textPane.addStyle("selected", regular);
    StyleConstants.setBackground(s, Color.YELLOW);
    public static void main(String[] args) {
    JFrame frame = new SelectedText();
    frame.addWindowListener(new WindowAdapter() {
    public void windowClosing(WindowEvent e) {
    System.exit(0);
    frame.pack();
    frame.setVisible(true);
    S.L.

  • Place a line above my selected text only

    I have two groups of words that need a line above them...
    "Patient Name" 
    and
    "Date"
    How do I do this?  Do i draw a line or is there a simplier way to keep the lines at the same distance and grouped when I move them?
    Page '09, mac book pro Lepord

    You may insert your piece of text in a single cell table.
    Yvan KOENIG (VALLAURIS, France) samedi 7 janvier 2012
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2

  • How can I get the tab key to select text fields only?

    Since upgrading to Firefox 4 on Windows, the tab key functions differently. How do I change it so that it only selects text input fields?

    The answer is:  The bug is in the UI.  Speech recognition was enabled, by default it uses the bare escape key as a "mic on" indicator, and it does not leave any trace in the keybord configuration.  So that is the bug.  It needs to leave a trace there, a la: "X Listen-for-voice-command  ^" under Mission Control.

  • How do I select text in a PDF document?

    I have a text-based PDF document, but I can only select text by restarting the reader. Once I select "Take a Snapshot" I can't select text anymore. How do I switch back to select text? I tried right-clicking on the document but I don't see any "selection" tool. I am using 11.0.3 under Win 7.

    Just tested this (Reader 11.0.3 on Windows XP), and your scenario is exactly so.
    I have been able to go back to get the Select Tool by clicking on the Highlight tool in the Toolbar, then right-clicking on the document.
    But it's definitely a bug in my view.

  • How do I select text from multiple pdf pages using Microsoft Document Imaging

    Hello.  I have scanned 3 pages and saved to pdf, now in Microsoft Document Imaging I can only select text from the first page and cannot select text from the other 2 pages.  Is there a way to select multiple pages?
    Thank you.
    Cat

    Why don't you ask in a MS forum? This forum is for an Adobe product and I have no idea why you are asking about Microsoft Document Imaging here.

  • Shell cmd to take selected text as stdin

    I'm trying to find a utility that I can use on a shell command line to
    take selected text in any CDE/Solaris as stdin and just copy to stdout. What API can I use if I write this in java?
    Any easier way to pipe selected window text into a program (e.g. lp)?
    There used to be a get_selection command in Sun4, but it doesn't work in Sun5.
    -willy
    get_selection | lp

    Ok, let me try this again.
    I have a CDE windowing system running. On one of the windows, I simply select
    text. It could be a shell window, a textedit window or whatever.
    The old sun4 get_selection solution did not require pasting into the clipboard.
    If I use cat in the way the responder suggests, then I need to copy and paste into the shell window as input to cat filling up the shell window unnecessarily. The window buffer may be limited which could cause overflow of desired lines.
    Simply by selecting the text (which is now highlighted), get_selection would use that text as it's stdin so I can pipe it to any other program such as lp or save it in a file, e.g. get_selection > file.txt or get_selection | lp.
    Having to juggle a temporary file is extra steps.
    This is so basic, I am surprised it is missing from the current Sun offerings.
    Also I tried to find the best Forum for user interface questions and to my surprise, there were none I could find. This forum was my best guess. Any other forum suggestions for this kind of question.
    I didn't have the source for get_selection and it doesn't work in solaris 7.
    I also searched for the API to access the selected text (the same text that 'copy' operates on), but couldn't locate it for use in my own program.
    thanks for the responses so far.

  • Design View - Can't Select Text, Only Divs

    This is a page I did not build, and I hope I can describe this properly. Here's the published page -
    www.wheeltime.com
    I'm in CS4 and there are two things going on when trying to edit in design view. The first is I can't select text of content. Clicking to select said content, say a line of text or a word, selects and highlights the entire div container and all the content within in one big chunk. Why is DW not letting me select the actual content? This is the first time I've enver encountered this issue. 
    This is the same for all the div ontainers on the page. But another, perhaps related problem, has to do with this content area. In design view, there's a fixed height, so not only can I not select the content, but I can't see it all. It's OK in the browser, expands as it should. I've looked at all the properties anywhere and don't see any height attribute anywhere, especially those that enclose this area of content.
    One this that has be wondering - this content area is warpped in a "main-content" div, with a class applied. But this div has no corresponding entry or properties in the style sheet. I can see where a div can be used that has no specific properies of it's own, but is it OK to not be mentioned at all in the style sheet? And can this affect what's going on in design view editing?
    So, I guess the question is - what is governing this inability to edit in Design view?  Thank you in advance!!

    Have you tried double clicking the content?
    I'm not sure what causes this exactly, but I downloaded your page and ran it in my DWCS4. It did the same thing until I double clicked the content of the divs. That allowed me to select it without issue from that point on.
    It may have something to do with the content being wrapped in <span> tags within each <div>.
    Onto your other question, your <div id="main-container"class="container"> is being affected by the .container class in your style.css file rather than a #main-container id.
    EDIT: HTML id's like <div id="main-content"> serve to identify elements for many purposes, not just css. There is no problem with giving an element an id simply for organizational purposes, though usually they are used as targets for javascripts, css or php scripting purposes.

  • JTextPane first line read only

    Hi all!
    I'm a beginner in java programming, that said im trying to make a simple text editor (who isn't?), it will be a part of another larger application, nevertheless this editor is a main component, just need some simple editing tips.
    I want to use a JTextPane for the editable surface, this is working fairly well but i am not able access other lines in the editor except from the first one. Meaning that when containing a large piece of text, my JTextPane is only able to edit the first line: For instance the caret will only show it self on the first line, I can write new letters, but only on the first line and i can erase them and so on. What am I missing? Have checked around many places for solutions
    To sum it up; I want to edit every line in my JTextPane instead of just the first one :)

    Ok! thanks a lot for the good advice, ant help is most appreciated. :-)
    Here is a piece of code that demonstrates my problem. Hope it brings insight! Try to write a line of text, then press enter to go to the next line, most probably you will find yourself unable to edit this line.
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTextPane;
    import javax.swing.SwingUtilities;
    public class Test implements Runnable
         public static void main(String[] args)
              SwingUtilities.invokeLater(new Test());
         public void run()
              JPanel cP = new JPanel();
              JTextPane tP = new JTextPane();
    JScrollPane sP = new JScrollPane( tP );
    tP.setPreferredSize(new Dimension( 400 , 400 ) );
              sP.setPreferredSize(new Dimension( 300 , 300 ) );
              tP.setEditable(true);
              cP.add(sP);
              JFrame f = new JFrame();
              f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
              f.setContentPane( cP );
              f.setLocationRelativeTo( null );
              f.setVisible( true );
    }

  • Can no longer select text in email template or read only field with mouse using IE or Firefox?

    Hi Guys,
    I can no longer select text in email template or read only field using my mouse in IE or Firefox anymore. We are using CRM 2011 rollup 18 applied with IE 11 and the latest version of Firefox. We only applied roll up 18 in Feb when this issue began.
    Thanks
    Dave
    David Kelly

    When you have a problem with one particular site, a good "first thing to try" is clearing your Firefox cache and deleting your saved cookies for the site.
    (1) Bypass Firefox's Cache
    Use Ctrl+Shift+r to reload the page fresh from the server.
    (You also can clear Firefox's cache completely using:
    orange Firefox button ''or'' Tools menu > Options > Advanced
    On the Network mini-tab > Cached Web Content : "Clear Now")
    (2) Remove the site's cookies (save any pending work first) using either of these. While viewing a page on the site:
    * right-click and choose View Page Info > Security > "View Cookies"
    * Alt+t (open the classic Tools menu) > Page Info > Security > "View Cookies"
    Then try reloading the page. Does that help?
    These features rely on JavaScript, and it sounds as though you have scripting enabled if you get (the wrong) color changes. Some add-ons might alter the way scripts operate, so a standard diagnostic to bypass interference by extensions (and some custom settings) is to try Firefox's Safe Mode.
    First, I recommend backing up your Firefox settings in case something goes wrong. See [[Backing up your information]]. (You can copy your entire Firefox profile folder somewhere outside of the Mozilla folder.)
    Next, restart Firefox in Firefox's Safe Mode ([[Safe Mode]]) using
    Help > Restart with Add-ons Disabled
    In the dialog, click "Start in Safe Mode."
    If those features work correctly, this points to one of your extensions or custom settings as the problem.
    To also disable plugins, you can use this page:
    orange Firefox button ''or'' classic Tools menu > Add-ons > Plugins category
    Any change?

  • Why does my 2012 Retina Macbook Pro's trackpad become extremely unresponsive after I plug in a USB mouse? The only trackpad command that works is the left click, I can't select text or press down and hold the trackpad to do anything else until I restart.

    My trackpad becomes REALLY unresponsive after I plug in a USB mouse. It seems like the cursor is broken and stuck on a permanent left click or something. I'm unable to select text or do any other sort of action that requires you to hold down the trackpad and drag. Mouse icons don't update as I scroll over different text and links. The trackpad is usually stuck in this unresponsive state until I restart my macbook which is extremely inconvenient if I have to do this after every time I use a USB mouse. Are there any fixes to this?

    Melophage,
    I don't leave it outside. Usually when I leave it overnight, I do so under the same conditions as when I leave it plugged in, and this morning I only left it for about an hour in my house and it did the same thing.
    LowLuster,
    I actually have a new hard drive I bought a while back and have been meaning to switch it out with the one that's in there now. I'll follow your instruction, then make the switch I had planned on and report back.

  • After placing a new text box in my document, typing new text, clicking away, then coming back to edit the text, I am unable to get my cursor to reappear within that text box. I can only select the box itself. I cannot select the text. Where is my cursor?

    After placing a new text box in my document, typing new text, clicking away, then coming back to edit the text, I am unable to get my cursor to reappear within that text box. I can only select the box itself. I cannot select the text. Where is my cursor?

    Even simpler than that.
    Clicking once in a text box selects it.
    Clicking once in a selected text box places the insertion point in the box.
    The clicks do not need to be close enough in time to be read as a double click.
    The same behaviour applies to table cells in Pages and in Numbers.
    Regards,
    Barry

Maybe you are looking for

  • Error Message: Code could not be generated successful​ly for the VI

    I created a simplified model of an 8-pole DC servo motor with friction brakes that drives an actuator through a gear train. I can't get past the subject error message. The error is about the VI named ""Sermat 3-Phase 8-Pole Motor with Friction Brake"

  • 2007 Mac Mini Dropping WIFI constantly

    Hello, I have a mid-2007 Mac Mini with Snow Leopard installed, and it's located in a room about 20 feet away  from the access point. The connection to the room has never been that great for the Mini, but my iPhone 4S for example has no problem connec

  • PPR error

    Hello, I've been working on a small ADF application (started in JDev 11.1.1.3 and, now, on 11.1.1.4). It works very well in the Integrated WLS and also works well in our many test environments but, when we put it in production, we are getting repeate

  • Can we change the location of the SharePoint Farm created by the "wizard"?

    If we use the wizard to create a SharePoint farm and we pick "East US", can we change it after the farm is created to a different location? JTB

  • Wich css code ive missed..

    I have place an I like button from facebook on my site. With Css ive tried to position the button on my page. I need to place it a litlle higher but i cant figure outr which code ive have to use. Please help... http://www.dorff.nl/index.html Regards