How to implement custom view of certain elements in a JTextPane?

Hi. I'm writing an application with a JTextPane in which I want to allow a style or attribute to be added to an (arbitrary) span of text, which will then result in a rectangle being drawn around that span of text. But I'm not sure how to do this.
I figure it will be necessary to extend one of the subclasses of View, but I'm not sure how to work that into my Document. Will I have to create a custom ViewFactory, or a custom EditorKit? Not sure I'd know how to do that.
Any pointers would be much appreciated.
Cheers,
Gregory

Here's the version I came up with. For some reason the width and height parameter of the two methods have a slightly different meaning which through me off for a while. Seems silly to me. Anyway it appears to work now:
import java.awt.*;
import javax.swing.*;
import javax.swing.text.*;
public class RectangleHighlighter extends DefaultHighlighter.DefaultHighlightPainter
    public RectangleHighlighter(Color color)
        super( color );
    public Shape paintLayer(Graphics g, int offs0, int offs1,
        Shape bounds, JTextComponent c, View view)
        Color color = getColor();
        if (color == null)
            g.setColor(c.getSelectionColor());
        else
            g.setColor(color);
        if (offs0 == view.getStartOffset() && offs1 == view.getEndOffset())
            // Contained in view, can just use bounds.
            Rectangle alloc;
            if (bounds instanceof Rectangle)
                alloc = (Rectangle)bounds;
            else
                alloc = bounds.getBounds();
//            g.fillRect(alloc.x, alloc.y, alloc.width, alloc.height);
            g.drawRect(alloc.x, alloc.y, alloc.width - 1, alloc.height - 1);
            return alloc;
        else
            // Should only render part of View.
            try
                // --- determine locations ---
                Shape shape = view.modelToView(
                    offs0, Position.Bias.Forward, offs1,Position.Bias.Backward, bounds);
                Rectangle r = (shape instanceof Rectangle)
                    ? (Rectangle)shape : shape.getBounds();
//                g.fillRect(r.x, r.y, r.width, r.height);
                g.drawRect(r.x, r.y, r.width - 1, r.height - 1);
                return r;
            catch (BadLocationException e)
                // can't render
        // Only if exception
        return null;
    public static void main(String[] args)
        JTextPane textPane = new JTextPane();
        textPane.setText( "one\ntwo\nthree\nfour\nfive\nsix\nseven\neight\n" );
        JScrollPane scrollPane = new JScrollPane( textPane );
        //  Highlight some text
        RectangleHighlighter cyan = new RectangleHighlighter( Color.CYAN );
        RectangleHighlighter red = new RectangleHighlighter( Color.RED );
        try
            textPane.getHighlighter().addHighlight( 8, 14, cyan );
            textPane.getHighlighter().addHighlight( 19, 24, red );
        catch(BadLocationException ble) {}
        JFrame frame = new JFrame();
        frame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
        frame.getContentPane().add( scrollPane );
        frame.setSize(300, 200);
        frame.setVisible(true);
}

Similar Messages

  • How to Implement custom share functionality in SharePoint 2013 document Lib programmatically?

    Hi,
    I have created custom action for Share functionality in document library.
    On Share action i'm showing Model pop up with Share form with addition functionality.
    I am developing custom share functionality because there is some addition functionality related to this.
    How to Implement custom share functionality in SharePoint 2013  document Lib pro-grammatically?
    Regards,
    - Siddhehswar

    Hi Siddhehswar:
    I would suggest that you use the
    Ribbon. Because this is a flexible way for SharePoint. In my project experience, I always suggest my customers to use it. In the feature, if my customers have customization about permission then i can accomplish this as soon
    as possible. Simple put, I utilize this perfect mechanism to resolve our complex project requirement. Maybe we customize Upload/ Edit/ Modify/ Barcode/ Send mail etc... For example:
    We customize <Edit> Ribbon. As shown below.
    When user click <Edit Item>, the system will
    render customized pop up window.
    Will

  • How to implement Custom Authentication and Authorization in Oracle SOA 11g

    Can anyone please tell me, how to implement Custom Authentication in Oracle SOA 11g ?
    Because in Oracle SOA 10.1.3.4 , i have implemented this custom authentication and authorization by implementing BPMAuthenticationService, BPMAuthorizationService, BPMIdentityService to verify againt my database systems.
    implementation classes like the mentioned below
    1).
    public class SampleAuthenticationService extends SampleServiceBase implements BPMAuthenticationService {
    2).
    public class SampleAuthorizationService extends SampleServiceBase implements BPMAuthorizationService {
    3).
    public class SampleIdentityService extends SampleServiceBase implements BPMIdentityService {
    Please help me to implement the authentication and authorization in Oracle SOA 11g .
    thanks in advance

    To start with please go through following document
    http://docs.oracle.com/cd/E21764_01/integration.1111/e10231/adptr_jms.htm
    http://docs.oracle.com/cd/E23943_01/integration.1111/e10231/adptr_file.htm
    Regards
    Arpit

  • How to implement the View V_SEPA_CUST in SAP 4.7 ?

    Hi SAP Experts,
    We are going to implement SEPA in our project and currently using SAP 4.7.
    Is there any way to implement the View V_SEPA_CUST in SAP 4.7.
    I came to know that there is an OSS Note available for this implementation but I couldn't find the same.
    Please suggest me how to Implement the View V_SEPA_CUST in our SAP system, since we need this View for SEPA implementation.
    Many Thanks in Advance.
    Yogesh.
    Moderator message: one thread only per issue, please.
    Edited by: Thomas Zloch on Jan 31, 2012

    Dear Yogesh,
    SAP has just recently released a note you might want to consider: 1834272. One of the preliminary notes for this note is 1784060...
    This works for SAP 6.4. I can not help you where it is specifically related to SAP 4.7
    Hoping it is of use.
    Best regards,
    Raymond

  • How to implement custom Model Class in Oracle ADF?

    I am using Oracle ADF for one of my project and i am using Query component of ADF. For given tables the query component creates view objects and maps the relations. ADF uses its own custom model class for this component and it should understand the DB tables. But for my project i have no access to database. All i can do is pass a string or object/query to the existing (custom) Java class/object, and this model class formulates query and queries the database and returns the value to my Java class. I have to display these results using ADF to the front end. Is There a way to achieve this? Can i replace/override the existing Model class of ADF. If so how?
    Thanks in advance for your help.

    Hi, there:
    Best thing to do is to start with the default login.html page, and then modify it. The login screen is fairly complex and it's easy to just miss a JS function you need to call. To get to default page, you would need to do one deploy (to simulator or whatever), and then look for login.html page in the temporary Xcode or Android project generated from the deployment. It should be under the "deploy" directory in your JDev workspace.
    You can also see all the framework JS files and CSS files that way as well.
    We have had customers implementing custom login screen so we know it can work, but they all had to start with the default login screen and then modify it.
    Thanks,
    Joe Huang

  • How to implement container with dividers between elements?

    What is the correct way to implement custom container with dividers between element in Flex 4 Spark architecture? In Flex 3 I would add dividers in rawChildren array and in updateDisplayList function I would arrange position of dividers and children. I can't do this now because there is no rawChildren and I can't add dividers as elements, because dividers are internal details of control and they should not be available to user. I thought to add second group with dividers, but the layout of splitters depends on the layout of actual content. With new model of separated layouts for Groups I don't know how do this correctly.  
    Thanks, Aleksey

    What is the correct way to implement custom container with dividers between element in Flex 4 Spark architecture? In Flex 3 I would add dividers in rawChildren array and in updateDisplayList function I would arrange position of dividers and children. I can't do this now because there is no rawChildren and I can't add dividers as elements, because dividers are internal details of control and they should not be available to user. I thought to add second group with dividers, but the layout of splitters depends on the layout of actual content. With new model of separated layouts for Groups I don't know how do this correctly.  
    Thanks, Aleksey

  • How to implement Inline Views in ODI?

    Hi,
    How to implement the following query (inline view) in ODI?
    Query:
    SELECT *
    FROM Table_one t1,
    (SELECT * FROM Table_two (includes some where conditions) t2
    WHERE conditions;
    How to set the conditions at the table level (not at the interface level) i.e., How to set the conditions used in Sub Query Table_two in ODI?
    Thanks in Advance,
    -Vency

    there is no native way to use hierarchical queries.
    you will have to modify KM
    It depends on your exact needs.

  • 10.6.6 - How to set custom view options for specific folders

    How is it that Windows has had the ability to ability to set custom folder view options forever and OSX can't. What is the big deal? Just do it. Whenever I set the folder view options it changes the view for all the folders. I can do folder specific changes as long as the finder window is open then I close it and open it again every folder is the same again. It's just an annoyance and it's something so rudimentary it's embarrassing.

    Try the following:
    I want to have, say, one folder in list view
    Open that folder, set it to list view, type command-J, and in the view-options window that opens, check the box at the top for "Always open in list view".
    then the subfolder of that folder I want to have in cover flow view. permanently.
    Open that folder, change it to cover-flow view, and in the view-options window check the box at the top for "Always open in cover-flow."
    Those two folders should "remember" the custom views that were set for them.
    There's additional discussion about the meaning of the"Use as defaults" button in this thread
    http://discussions.apple.com/thread.jspa?messageID=13063792
    My own take is that folders that have not been customized by checking the "Always open in xxx view" box will by default open in the same view (icon vs list vs column, etc) that was in effect for the previously opened folder. *Within each view*, you can set the default parameters (text size, etc) for a new folder by setting up a folder the way you like and then checking the view options box for "Use as defaults" at the bottom.

  • How to add Custom View to GP Runtime Views

    Hi All,
    I would like to add custom view to my GP process.
    In GP runtime mode the numbers you see on left hand side like "run103" "run002" are confusing to users. I would like to have appropriate name/description instead.
    I understand that I can add Custom view to Runtime Views, but when I am editing a process "Add Custom View" button is always disabled.
    Why that button is always disabled?
    How do I define Custom View for a process?
    Thanks,
    Abhay

    Hi Abhay,
    this is a bug in SP7 which is fixed in the last patch. You can download it from the Market Place.
    Best regards,
    David

  • How to Import Custom Views and JSPs to ALBPM Enterprise

    Hi,
    I am using ALBPM 5.7. I have developed a custom view in Studio. When I publish and Deploy the Project in ALBPM Enterprise (WebLogic 9.2), I check true the Import Custom JSPs and Views (or similar terminology). But when I login to the portal after installing the EAR, the view is not listed in my work pane.
    Also, in one of the Interactive Activity I am calling a JSP, which gives a Null Pointer Exception when execute the instance, In my opinion, the Custom JSP is not deployed.
    I have also copied the JSP file in location \bea\ALPBM5.7\j2eewl\webapps\portal\customjsp\
    Please suggest as how do I deploy the View and JSP
    Thank you,
    Regards
    Jayant
    Edited by jayantbit at 06/19/2008 8:01 AM
    Edited by jayantbit at 06/19/2008 8:21 AM

    Hi Mohamed,
    Please check below link.
    What is Drag and Relate in SAP Business One - YouTube
    https://help.sap.com/saphelp_sbo882/helpdata/en/45/100314cf465d7ae10000000a11466f/content.htm
    https://help.sap.com/saphelp_sbo882/helpdata/en/45/10ff71cf465d7be10000000a11466f/content.htm
    SAP - SAP Business One: Your Solution for Generating Custom Reports
    Hope this helps
    Regards::::
    Atul Chakraborty

  • Outlook 2013 (how to share Custom "Views" for shared Contacts/Journals)

    Environment:  Office 2013 Client (Office 365 E3)
    I have shared Contacts and Journals with other users.
    I have a custom View for each, how do I share the "View"?

    Hi,
    Custom view won't be shared when you share your Contacts or Journals. You'll need to copy the views you want to share to a pst-file and then share the pst file to others.
    To do this, please refer to the following link and look at the "Method 3: Copy views to a Views_backup.pst" section:
    http://www.outlook-tips.net/how-to/copy-outlook-custom-views/
    Please Note: Since the web site is not hosted by Microsoft, the link may change without
    notice. Microsoft does not guarantee the accuracy of this information.
    You can also refer to the video tutorial at the end of the article for detailed steps.
    Regards,
    Steve Fan
    TechNet Community Support
    It's recommended to download and install
    Configuration Analyzer Tool (OffCAT), which is developed by Microsoft Support teams. Once the tool is installed, you can run it at any time to scan for hundreds of known issues in Office
    programs.

  • How to implement custom logging using log4j in Webcenter Portal Application

    I need to implement custom logging and export it to a new log file in Oracle 11.1.1.5 (Webcenter portal application). Please tell me the steps to implement this functionality.

    Please post questions for WebCenter Portal in it's own forum:
    WebCenter Portal

  • How to implement custom skin in JavaFX 2.0?

    To implement custom skin, I extend TextFieldSkin (in com.sun.javafx.scene.control.skin.*) class, but I don't know which methods to overwrite, anyone can provide some sample codes? Thanks!

    Hi,
    You can implement Skin interface or extend SkinBase class. I made some controls on my blog http://jojorabbitjavafxblog.wordpress.com/ but i still have not updated code to build 40. In my opinion the easiest way is to make first skin for Button class for example add text and Rectangle.

  • How to edit customizing view in production system?

    Hi,
    I wonder if it is possible to edit customizing view (ex: tcode OAV8) directly in production system. I need a method that doesn't require repair.
    Any help will be appreciated..

    Hey
    You can copy view V_T087G to ZV_T087G. After you have to create a new table maintenance for this view. The new table mainteance will have a Z function module so you can select in the "Dialog Data Transport Details" the flag "no user recording routine" instead of "Standard, recording routine".
    After you have to call this table maintenance from Sm30 or from a transaction.
    Regards

  • How to implement custom field renderer?

    I'm trying to create a custom field renderer that will render certain database fields as checkboxes in HTML. I'm using the Data Web Beans/JSP approach. In my view object I have added a "Boolean" property to the attributes that represent boolean type fields (e.g., field Warranty to indicate if an asset is under warranty). I have created a CheckBoxField() class similar to the TextField() class, and call it if the attribute is a boolean, but I can't figure out how to set the custom field renderer. When the program runs, it still uses the TextField renderer. The JDeveloper online documentation doesn't say anything about it. Is there a sample program or some other documentation that implements a custom field renderer?

    Hi,
    this document in addition
    http://www.oracle.com/technology/products/jdev/howtos/10g/jaassec/index.htm
    has a list of LoginModules, one that authenticates against physical database users
    Frank

Maybe you are looking for