How to change attributs of a piece of Document ?

Hello,
I have a JTextPane and a Document which has inherited of DefaultStyleDocument.
When the user has selected a piece of the text, I want to make him changes a few attributs
I looked at the sample TextComponentDemo, but all attributs are specified in menu items (so they are quite static).
In fact, users want to :
1. Select part of the text
2. Click on a menu item for example "Change Color" which invokes the JColorChooser Class
3. change the text after having selected a color.
More generally, this applies also to font name from the font family, font syle and font size.
I noticed that there is a class name AttributSet, but I don't know how to manipulate this set (especially where to find attribut names).
Thanks in advance for suggestions, examples, or pointers to good documentations
Gege

but all attributs are specified in menu items (so they are quite static).Yes, but the Action is created using a color Object. So just create an action using the color selected from the JColorChooser and then invoke its actionPerformed() method:
Action foreground = new StyledEditorKit.ForegroundAction("", colorFromColorChooser);
foreground.actionPerformed(null);

Similar Messages

  • Even your help is confusing how do i find instructions on how to change a pdf to a word document i d

    even your help is confusing
    how do i find instructions on how to change a pdf to a word document
    I purchased this software and now I can't find it

    Thanx!!!
    that is, if there are entries in document "hello 1234", then the search all words will identify it as two words "hello" and "1234". and then I check with regular expressions where the numbers.. ?
    ps. and I have not found yet any command, that replace the founded text from javascript))
    yes.. in acrobat X pro.. tools-protection-search&remove is also avaible....! (but, no regular in search string.. to bad...)
    thank you!

  • How to change attributes of Objects of all windows in a MDI application

    Hi,
    I have a MDI application to draw Object. In these MDI windows I can modify attributes of Object like color, size... Now I want to create an option, when the user change or modifies attribute of Objects in a window, so it allow to change attributes of objects in all windows. I don't know how I can do it, please help me. Thanks

    Allow your objects to alias mutable attribute objects.
    import java.awt.*;
    import java.awt.event.*;
    import java.awt.geom.*;
    import java.util.*;
    import javax.swing.*;
    import java.util.List;
    public class Example extends JPanel {
        private List bangles = new ArrayList();
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2 = (Graphics2D) g;
            for(Iterator j=bangles.iterator(); j.hasNext(); )
                ((Bangle)j.next()).paint(g2);
        public void addBangle(Bangle bangle) {
            bangles.add(bangle);
            repaint();
        public static void main(String[] args) {
            JFrame.setDefaultLookAndFeelDecorated(true);
            JDialog.setDefaultLookAndFeelDecorated(true);
            Example app = new Example();
            JFrame f = new JFrame("Example");
            Container cp = f.getContentPane();
            cp.add(app, BorderLayout.CENTER);
            cp.add(Controller.create(app), BorderLayout.NORTH);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(800,600);
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    class Controller {
        private Shade shade1 = new Shade(Color.GREEN), shade2 = new Shade(Color.RED), currentShade=shade1;
        private Example modelView;
        public static JComponent create(Example modelView) {
            return new Controller(modelView).createUI();
        private Controller(final Example modelView) {
            this.modelView = modelView;
            modelView.addMouseListener(new MouseAdapter(){
                public void mousePressed(MouseEvent evt) {
                    Rectangle shape = new Rectangle(evt.getX(), evt.getY(), 20, 20);
                    modelView.addBangle(new Bangle(shape, currentShade));
        private JComponent createUI() {
            ButtonGroup bg = new ButtonGroup();
            final JToolBar tb = new JToolBar();
            final JRadioButton rb1 = createRadio("Shade 1", true,  shade1, bg, tb);
            final JRadioButton rb2 = createRadio("Shade 2", false, shade2, bg, tb);
            JButton btn = new JButton("Change color of selected shade");
            btn.setContentAreaFilled(false);
            btn.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    Color newColor = JColorChooser.showDialog(tb, "Choose new color", currentShade.getColor());
                    if (newColor != null) {
                        currentShade.setColor(newColor);
                        if (currentShade == shade1)
                            rb1.setForeground(newColor);
                        else
                            rb2.setForeground(newColor);
            tb.add(btn);
            return tb;
        private JRadioButton createRadio(String text, boolean selected, final Shade shade, ButtonGroup bg, JToolBar tb) {
            JRadioButton rb = new JRadioButton(text, selected);
            rb.setContentAreaFilled(false);
            rb.setForeground(shade.getColor());
            rb.addActionListener(new ActionListener(){
                public void actionPerformed(ActionEvent evt) {
                    currentShade = shade;
            tb.add(rb);
            return rb;
    class Bangle {
        private Shape shape;
        private Shade shade;
        public Bangle(Shape shape, Shade shade) {
            this.shape = shape;
            this.shade = shade;
        public void paint(Graphics2D g2) {
            g2.setColor(shade.getColor());
            g2.draw(shape);
    class Shade {
        private Color color;
        public Shade(Color color) {
            this.color = color;
        public Color getColor() {
            return color;
        public void setColor(Color color) {
            this.color = color;
    }

  • How to change the title of an existing document?

    I have looked in online manuals and there are no headings for this.  I wish to change the title of an existing documents but can find no way to do so.  Any one have help on this? 

    You can also change the file name in Finder.
    peter

  • How to change attributes of multiple devices ?

    This is something I thought would be straightforward but for the life of me I can not see how is it done in ZCM. I just want to set a property for a number of devices - based on a manual selection or maybe search results. E.g. I would like to set a location for all devices added on a given day. I can easily do a search to bring up a list of the devices but can not see a way to set an attribute for those. Am I missing something obvious here ?
    While on it, is it possible to set device attributes from bundles ? E.g. as a part of post-imaging process I would like to set the location or the department for that device from a linked bundle.

    Originally Posted by atrofimov
    This is something I thought would be straightforward but for the life of me I can not see how is it done in ZCM. I just want to set a property for a number of devices - based on a manual selection or maybe search results. E.g. I would like to set a location for all devices added on a given day. I can easily do a search to bring up a list of the devices but can not see a way to set an attribute for those. Am I missing something obvious here ?
    Guys, "cannot be done" would still be a valid answer :) I doubt it can't be done, after all it seems to me like a pretty basic feature. I would even be happy to change the attribute for a group of devices - e.g. create a dynamic group then change location for the members .. but I can't see a way of doing that either.

  • How to change attribute "read_only" of a inputfield in a table?

    Hi, experts,
    action:
    1.Create a table with name " A_TABLE" in the layout in a view.
    2.Binding some fields from a structure to the table.
    3.Field "Checkbox" is a checkbox type and field "input" is a inputfield type with readonly in the table "A_TABLE" .
    4.I hope: When selecting a checkbox in the "Checkbox" colume in a row in the table, the field "input"  corresponding will be changed readonly.
    The follow is my code: When select Field "Checkbox" , the method is invoked.
    method ONACTIONCLICK4DISDESC .
       data view           type ref to if_wd_view.
       DATA input_desc     TYPE REF TO CL_WD_INPUT_FIELD.
       data tab            type if_BIDDING_LIST_VIEW=>elements_ONSURVEY.
       data struct         type if_BIDDING_LIST_VIEW=>element_ONSURVEY.
    I have set "wd_this->m_view = view" in the method wddomodify and add m_view to the attribute of the
      "viewBIDDING_LIST_VIEW" .
       view ?= wd_this->m_view.
       input_desc ?= view->GET_ELEMENT( `TABLE_INPUT_EDITOR` ).
       input_desc->SET_READ_ONLY(  EXPORTING  value = abap_false ).
    endmethod.
    result:
    when I select a checkbox in the "Checkbox" colume in a row in the table, all field "input" is read and write.
    How can I do it ?
    Best regards,
    tao

    Hello Wang,
    You need to bind the readOnly attribute of the input field to a newly to created attribute beneath the dataSource node of the table within the context. That way, each input field of each row of the table can have a different value for readOnly.
    Best regards,
    Thomas

  • How to change attributes of fields ?

    hi evryone,
       I am new to  ERP HCM (HR) . I have used standard services as leave request and all. In Leave Request i want to change the attributes of the fields on user entry. Is this possible to be done? if yes , how?  how can i see the structure coming onfront ? Where can we maintain these fields at backend?
    thanks in advance.

    Hi evryone,
        Please help me for this.

  • How to change attributes of HTML table in HTMLDocument

    Hi
    I am trying to change background of table cell but unsuccessfully. First of all I did not found any suitable method in API so I have to inherit HTMLDocument and make my own
    public static class ExtendedHtmlDocument extends HTMLDocument {
    public void replaceAttributes(Element element, AttributeSet attributes, HTML.Tag tag) {
    try {
      writeLock();
      int offset = element.getStartOffset();
      int length = element.getEndOffset() - offset;
      MutableAttributeSet mutableAttributes = (MutableAttributeSet) element.getAttributes();
      mutableAttributes.removeAttributes(attributes.getAttributeNames());
      mutableAttributes.addAttributes(attributes);
      DefaultDocumentEvent changes = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.CHANGE);
      changes.addEdit(new AttributeUndoableEdit(element, attributes.copyAttributes(), true));
      changes.end();
      fireChangedUpdate(changes);
      fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
    finally {
      writeUnlock();
    }When I usethis code and dump exisiting document I see changes, e.g. I changed background in cell:
    private void setCellBackground(Element element) {
      SimpleAttributeSet set = new SimpleAttributeSet();
      set.addAttribute("bgcolor", "black");
      doc.replaceAttributes(element, set, HTML.Tag.TD);
      doc.dump(System.out);
      //editor.setText(editor.getText());
    } and extract from dump
    <html
      name=html
    >
        <table
          width=100%
            <td
              bgcolor=black
              name=td
            >But I do not see changes in the view, cell has the same background. The view is updated only if I uncomment last line "editor.setText(editor.getText())", but I think it is not good to update this way.
    Thanks.

    Here I put an example and you can play with different strange aspects of HTMLDocument implementation
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.text.*;
    import javax.swing.text.html.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    public class TableEditor implements ActionListener {
        private JEditorPane editor;
        private ExtendedHtmlDocument doc;
        public TableEditor(JEditorPane editor, ExtendedHtmlDocument doc) {
            this.editor = editor;
            this.doc = doc;
        public void actionPerformed(ActionEvent e) {
            Element element = doc.getCharacterElement(editor.getCaretPosition());
            Element parent = element.getParentElement();
            while (parent != null && !parent.getName().equals("td")) {
                parent = parent.getParentElement();
            if (parent == null) {
                JOptionPane.showMessageDialog(null, "Select cell to edit properties");
            } else {
                SimpleAttributeSet attributes = new SimpleAttributeSet();
                attributes.addAttribute(HTML.Attribute.BGCOLOR, "gray");
                attributes.addAttribute(HTML.Attribute.ALIGN, "right");
                doc.replaceAttributes(parent, attributes);
    //            doc.replaceAttributes(parent, attributes);
    //            editor.setText(editor.getText());
                doc.dump(System.out);
        private static class ExtendedHtmlEditorKit extends HTMLEditorKit {
            public Document createDefaultDocument() {
                StyleSheet styles = getStyleSheet();
                StyleSheet styleSheet = new StyleSheet();
                styleSheet.addStyleSheet(styles);
                ExtendedHtmlDocument doc = new ExtendedHtmlDocument(styleSheet);
                doc.setParser(getParser());
                return doc;
        public static class ExtendedHtmlDocument extends HTMLDocument {
            public ExtendedHtmlDocument(StyleSheet styles) {
                super(styles);
            public void replaceAttributes(Element element, AttributeSet attributes) {
                try {
                    writeLock();
                    MutableAttributeSet mutableAttributes = (MutableAttributeSet) element.getAttributes();
                    mutableAttributes.removeAttributes(attributes.getAttributeNames());
                    mutableAttributes.addAttributes(attributes);
                    int offset = element.getStartOffset();
                    int length = element.getEndOffset() - offset;
                    DefaultDocumentEvent changes = new DefaultDocumentEvent(offset, length, DocumentEvent.EventType.CHANGE);
                    changes.addEdit(new AttributeUndoableEdit(element, attributes.copyAttributes(), true));
                    changes.end();
                    fireChangedUpdate(changes);
                    fireUndoableEditUpdate(new UndoableEditEvent(this, changes));
                finally {
                    writeUnlock();
        public static void main(String args[]) throws Exception {
            HTMLEditorKit kit = new ExtendedHtmlEditorKit();
            final ExtendedHtmlDocument doc = (ExtendedHtmlDocument) kit.createDefaultDocument();
            StringReader reader = new StringReader("<table border='1' width='100%'>\n" +
                    "    <tr>\n" +
                    "        <td>Cell1-1</td>\n" +
                    "        <td>Cell1-2</td>\n" +
                    "    </tr>\n" +
                    "    <tr>\n" +
                    "        <td>Cell2-1</td>\n" +
                    "        <td>Cell2-2</td>\n" +
                    "    </tr>\n" +
                    "    <tr>\n" +
                    "        <td>Cell3-1</td>\n" +
                    "        <td>Cell3-2</td>\n" +
                    "    </tr>\n" +
                    "</table><p>paragraph</p>");
            kit.read(reader, doc, 0);
            final JEditorPane editorPane = new JEditorPane();
            editorPane.setIgnoreRepaint(false);
            editorPane.setEditable(true);
            editorPane.setEditorKit(kit);
            editorPane.setDocument(doc);
            JScrollPane scrollPane = new JScrollPane(editorPane);
            JPanel menu = new JPanel(new FlowLayout(FlowLayout.LEFT));
            menu.add(new JButton(new AbstractAction("Cell properties") {
                public void actionPerformed(ActionEvent e) {
                    new TableEditor(editorPane, doc).actionPerformed(e);
            JFrame frame = new JFrame();
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.getContentPane().setLayout(new BorderLayout());
            frame.getContentPane().add(scrollPane, BorderLayout.CENTER);
            frame.getContentPane().add(menu, BorderLayout.NORTH);
            frame.setSize(800, 500);
            frame.setVisible(true);
    }Look at actionPerformed implemetation I am going to change cell background and alignment - background is changed but alignment is not, when you uncomment second doc.replaceAttributes(parent, attributes) - it will work. In both cases align attribute exists in cell (look at the dump in system.out)

  • How to change default language in an existing document?

    I have created several documents, all with tables in them (lots of text in tables). All of these were created when the default language was English. As I am typing all of these documents in Australian English (same as British English) I am getting lots of red underlines on word that Pages thinks are incorrectly spelt.
    How can I do a global change of the text to Australaian English (or any other language for that matter). If I do Select All within the document it does not select the text in the tables so for the moment it looks like I have to select each cell individually to change the language. This will take hours, Surely there is a simpler method to to a global language change.

    Update all the styles after you have changed the language.
    Insert the cursor in the sample style > Styles Drawer > click on the red triangle next to the style > Redefine Style from selection
    Save your document. If you need this for future documents save as a template.
    You should have set your system language to Australian English and it would have defaulted to that.
    Peter

  • How to get attribute, such as Title, of Documents stored in WWDOC_DOCUMENT$

    Hi,
    I've created a portlet which reads from the WWDOC_DOCUMENT$ table and creates links to certain documents. However only the original filename and the Portal assigned numerical filename are stored within this table. I would like to be able to display the item title to users which was specified when the file was originally uploaded.
    Presumably somewhere there is another table which holds other attributes such as an items title, which is linked to WWDOC_DOCUMENT$ via a primary/foreign key.
    Can anyone help as to where this is?
    Thanks in advance.
    Dan

    pvujic wrote:
    Thanks, but how can I "fetch" the url from the image element?You've got to first get to the image element. But based on what you've posted though, with a little more coding, you should be able to succeed. Just give it a try! :)

  • Do you know how to change the Text Object for Billing Document?

    Hi,
    If you execute Transaction VOTX or VOTXn it will take you to Text Determination. The Billing Doc & Sales Document both has the VBBK as Text Object for me and is it like that for all.
    I need to change the Text Object to VBRK for Billing Doc, which is the ideal because I am using the Function Module READ_TEXT to retrieve text. This work perfectly for Sales Document which has VBBK as Text Object, but does not work for Billing Doc where it through as error message saying “Text 0020000021 ID 0002 language EN not found”.
    Thank You
    Kishan

    Hi kishan,
    For updating these text you can use FM 'SAVE_TEXT'.
    As for your problem, to get the parameter you need, go to the billing document, go to the text, and display it in plain page mode.
    Then you do 'GO TO' -> 'HEADER', and a pop-up window open with the parameters you need Obect type, ID, Name, ...
    Regards,
    Erwan.

  • How to change tab stops in a completed document with Pages?

    I switched from WordPerfect to Pages and have struggled with figuring things out. I have a membership list I do each year with names addresses, phones, etc. I used a right tab to put the phone numbers out on the right margin. Now I find my originally defined margins are off, and I want to change that right tab. I seem to be able to do this only one name at a time: very tedious. Is there a way to change it for the entire list all at once?

    Here is a short script allowing us to select every paragraph starting with a TAB character.
    Of course, we may edit it allowing it to select paragraphs matching an other criteria.
    --(SCRIPT selectparagraphs_starting_withtab]
    Apply this script to a Pages document.
    Every paragraph starting with a TAB character will be selected.
    You may aplly some settings to all of them in a single operation.
    Thanks to Axel Lutgens.
    le 25 juillet 2008
    property L : {}
    tell application "Pages"
    set my L to {}
    tell first document
    set N to count of paragraphs
    repeat with P from 1 to N
    if character 1 of paragraph P is tab then copy (a reference to paragraph P) to the end of my L
    end repeat
    end tell
    select my L
    end tell
    set L to {}
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE vendredi 25 juillet 2008 11:41:29)

  • How to change the name of the Portal DOCUMENT.

    I have some document like
    http://portal.co.com/pls/portal/docs/1/26024.GIF
    I want to rename the file name at the end to be something like
    http://portal.co.com/pls/portal/docs/1/1234.GIF
    How can I achieve this. Anything from the front end / browser window is preferred. I got some hint after doing some searching on this... like wwdoc_api.move_document... but dont know how to use this..
    Any pointers are highly appreciated.
    Thanks,
    -Raj

    Display the documents list, tap the Edit button, select the file you want to rename, and tap the Rename icon at the top (4th from the left, just to the left of the trash can).

  • How to change margins in Id, after a document is defined?

    We are designing a book in Id and already have a dcument defined.  We have searched high and low.  But we find nowhere to change the margins of the document, post-creation.  (Of course those options present themselves, during document creation itself.)
    Yes, we are newbies to Id and most appreciate the help.  Thanks.
    David Allen

    Hi,
    Select the master pages in the "Pages" panel and go to menu "Pages", sub-menu "Margins & columns" (I use a french version, so may be the translation is incorrect!).

  • Can't find how to change column properties in my CSS document

    So, I'm working on a pre-existing website someone set up, and need to make some adjustments to a couple of custom commands they made, RightCol and CenterCol. The problem is, I can't find any code relating to either in the CSS document. Is there something I'm missing here, an easier way to find them? A way to change both remotely without finding the code hidden in the CSS document? or am I just gonna have to make new commands from scratch?

    My wife had the same problem. Click on the tools icon in your web browser and go to the "zoom" feature. You can adjust the font size there.

Maybe you are looking for