Add Undo property to JTextPane

Hi
I am getting problem for adding UNDO functionality to jtextpane.My requirement is to undo or restore the data by clicking a button.
According to my application requirement i have to add multiple(as many as required) panels to a scroll pane dynamically.And these panels consist of a text pane and a combo box.when user will click on the undo button the data in the text pane should be restored.
For this i made a panel class(DynamicPanels in the code below which contains the text pane and combo boxes) and creating array of panel classes and adding these panels through loop.
The problem here is , as i am adding the panels dynamically. while trying to add any logic for undo in side the loop it is giving class cast exception ( by applying logic in different way null pointer exception as here the instances are created dynamically i.e runtime).
Please help me to overcome this issue.
Thanks.
//UndoInTextPaneFrame.java
import javax.swing.*;
import javax.swing.event.UndoableEditEvent;
import javax.swing.event.UndoableEditListener;
import javax.swing.text.Document;
import javax.swing.undo.CannotUndoException;
import javax.swing.undo.UndoManager;
public class UndoInTextPaneFrame extends JFrame{
    final static int NO_OFPANELS=10;
    DynamicPanels[] arrayOfPanels=new DynamicPanels[NO_OFPANELS];
    private javax.swing.JButton jButton1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    public UndoInTextPaneFrame(){
        jScrollPane1 = new javax.swing.JScrollPane();
        jPanel1 = new javax.swing.JPanel();
        jButton1 = new javax.swing.JButton("UNDO");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                System.out.println("UNDO button clicked");
        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Frame to add UNDO property");
        setSize(400,300);
        getContentPane().setLayout(new javax.swing.BoxLayout(getContentPane(), javax.swing.BoxLayout.Y_AXIS));
        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
        jPanel1.setLayout(new javax.swing.BoxLayout(jPanel1, javax.swing.BoxLayout.Y_AXIS));
        for(int i=0;i<arrayOfPanels.length;i++){
            arrayOfPanels= new DynamicPanels(i);
jPanel1.add(arrayOfPanels[i]);
//LOGIC FOR UNDO
// JTextPane txtPane=(JTextPane)arrayOfPanels[i].getComponent(0);
jScrollPane1.setViewportView(jPanel1);
getContentPane().add(jScrollPane1);
getContentPane().add(jButton1);
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new UndoInTextPaneFrame().setVisible(true);
class DynamicPanels extends JPanel{
final UndoManager undo;
private JTextPane jTextPane1;
private JComboBox jComboBox1;
private JScrollPane jScrollPane1;
public DynamicPanels(int number) {
jTextPane1 = new JTextPane();
jComboBox1=new JComboBox();
jScrollPane1=new JScrollPane();
Document doc = jTextPane1.getDocument();
undo= new UndoManager();
// Listen for undo and redo events
doc.addUndoableEditListener(new UndoableEditListener() {
public void undoableEditHappened(UndoableEditEvent evt) {
undo.addEdit(evt.getEdit());
try {
if (undo.canUndo()) {
undo.undo();
} catch (CannotUndoException e) {
jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
jScrollPane1.setViewportView(jTextPane1);
setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.X_AXIS));
add(jScrollPane1);
add(jComboBox1);

https://forums.oracle.com/forums/thread.jspa?threadID=2469362&tstart=0

Similar Messages

  • How to add the property file..ie(default.properties) to a webdynpro project

    Hi All,
    How to add the property file..ie(default.properties) to a webdynpro project.
    I urgently require the solution. Kindly get it for me.
    Regards
    DK

    Hi DK,
    this is described in the second Web Dynpro Java Tutorial
    <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/downloaditem?rid=/library/uuid/b1a3e990-0201-0010-aeb2-a2ef5bc3da8e">creating an Extended Web Dynpro Application</a>
    Regards, Bertram

  • Is it possible to add a property using variable in variable name?

    I want to query for a list of virtual machines within a folder, then create a menu of the host names using forms.  Since the list of machines is subject to change, I want to build the list each time the script is run, rather than build off a static
    list. 
    For each virtual machine I need to create the list of variables below:
    $hostnameX = New-Object System.Windows.Forms.checkbox
    $hostnameX.Location = New-Object System.Drawing.Size(10,20)
    $hostnameX.Size = New-Object System.Drawing.Size(100,20)
    $hostnameX.Checked = $true
    $hostnameX.Text = "Type"
    $hostnameX.Controls.Add($hostnameX)
    The location and size values need to be incremented but I think I can figure that part out.
    I can use New-Variable to generate the initial variable. But I receive errors using the same method to try to create a new property for the variable.
    $VMS = Get-Cluster MyCLUS | Get-vApp "My vApp" | Get-VM | Select Name,PowerState | Sort Name
    For ($i=0; $i -lt ($VMS.count); $i++)
    $VMS[$i].Name
    $VMGUEST = "$($VMS[$i].Name)" -replace("-","")
    New-Variable "CB$VMGUEST" "New-Object System.Windows.Forms.checkbox"
    New-Variable "CB$VMGUEST.Location" "New-Object System.Drawing.Size(10,20)"
    In the above, $CBVMGUEST1 =  New-Object System.Windows.Forms.checkbox which is what I want,  but $CBVMGUEST1.Location is not set.
    Is there way to add a property using a variable in the variable name?  Or any other suggestions on how to tackle this issue?

    Hi,
    maybe another approach is a bit easier.
    Use a hash-array like
    $CB = @{}
    $CB[$VMGUEST] = New-Object System.Windows.Forms....
    $CB[$VMGUEST].Location = New-Object System.Drawing....
    Mit freundlichen Grüßen Jens Kalski
    That's the correct answer.  Anytime you find yourself wanting to create variables named "Widget1", "Widget2", "Widget3", etc... it's a pretty clear indication that what you really need is a collection object of some sort.  That might be an array,
    a hashtable, or any other data structure for holding other objects, depending on your specific needs.

  • Add custom property restrictions in advanced search web part

    hi,
     I am having the default advanced search box web part in my ent.search center site collec. but as per my requirement i need to a  few items in the property restrictions dropdown in my advanced search web part.
    is this possible in sp 2013 e.t serach center  site collection?
    any help is  highly appreciated!

    Hi,
    Check this
    http://technet.microsoft.com/en-us/library/ff621097.aspx
    http://social.technet.microsoft.com/Forums/sharepoint/en-US/c25d418d-d4a2-47a3-9abe-c27656764843/how-to-add-custom-property-in-advanced-search-page?forum=sharepointgeneralprevious

  • Add a Property Dropdown menu in CSS panel, not showing all properties?

    Hi,
    So, I am sitting side by side at 2 machines...I have the same CSS style I created for a table. On the one machine, I go to add a property and choose border-collapse. All is fine. I go to the other machine and border-collapse is not there? Then, I realized the entire list is much shorter and is missing many properties? The shorten list starts with the background property...The long list on the good machine, starts with alignment-adjust (in other words, I am missing any property that starts with the letter a...plus many more).
    I trashed preferences but that didn't help.
    Has anyone else come across this problem?
    thanks
    babs

    HI Murray,
    Sorry for the late reply...was one of those weeks....
    Anyhow...Both DW apps are running CS5? Ironically, U never checked my home machine also running 5, and my CSS panel also starts with background properties. So I am missing a bunch of them as well. It's very odd. The inly thing I can think of, Is I purchased a few CSS templates to work with and I wonder, if when I loaded them on that computer, they added those extra css properties?
    It's a mystery.....

  • Add datetime property to "MetaInfo" field using SharePoint 2013 CSOM

    When uploading a file along with metadata using SharePoint FP RPC (using the "method= put document") it allows me to properly add datetime properties. My metainfo looks like this:
    "MetaInfo":"...MyCustomDate:TW|05 Jan 2015 12:58:31 -0000\r\n..."
    Then later on, when I try to update "MyCustomDate" property from the "MetaInfo" field using CSOM, it fails while updating it. (In this case I am using CSOM because I am updating some more fields and I want to avoid extra round-trips)
    After that update my metainfo looks like this:
    "MetaInfo":"...MyCustomDate:FX|0x01d028e7|0x4d1c4880\r\n..."
    Does anyone know why?, is there any workaround?
    Thanks

    Hi,
    If you want to add datetime property to "MetaInfo" field using SharePoint 2013 CSOM, the following code snippet for your reference:
    using (ClientContext context = new ClientContext("http://yourserver/"))
    context.Credentials = new NetworkCredential("user", "password", "domain");
    List list = context.Web.Lists.GetByTitle("Documents");
    ListItem oListItem = list.GetItemById(1);
    oListItem["MetaInfo"] = "MyCustomDate:TW|08 Jan 2015 12:58:31 -0000";
    oListItem.Update();
    context.ExecuteQuery();
    Best Regards
    Dennis Guo
    TechNet Community Support

  • Add meta property="go:image" to my blog entries

    How do I add <meta property="go:image" to my individual blog entries?
    The way I had it configured was working until yesterday - when the new BC update was released - and I am now getting this message from the FB Debugger
    Meta Tags In Body
    Your page has meta tags in the body instead of the head. This may be because your HTML was malformed and they fell lower in the parse tree.
    Please fix this in order for the tags to be usable.

    Liam -
    I disabled the beta features and that seemed to fix the problem this morning without adding the <head></head> ---- that seemed to work until it didn't...
    so I went and added <head></head> updated, check the source code - looked like it took the <head></head> tags but the FB Debugger scraper still came back with same error
    went back into the editor and it had removed the <head></head> tags
    I've tested a number of blog posts and commerce items - some work, some don't (could be old scrapes I suppose)
    I also had to switch from using the editor in Safari to Chrome to get the editor to update anything
    (To my knowledge I never actually enabled beta - noticed the editor change a month or so ago - I knew it was buggy after talking to support about that time, but this meta image tag was working till Friday so I hadn't disabled it)

  • How to Add Horizontal scrollbar to JTextPane

    when i try to add Horizontal scrollbar to JTextPane it is not apperaing..plase help me..
    nagesh

    I tried in all ways
    1)HORIZONTAL_SCROLLBAR_ALWAYS and VERTICAL_SCROLLBAR_ALWAYS
    2)JTextPane textPane = new JTextPane();
    JScollPane scroller = new JScrollPane(textPane);
    or :
    3)JScollPane scroller = new JScrollPane(textPane, VERTICAL_SCROLLBAR_ALWAYS, HORIZONTAL_SCROLLBAR_ALWAYS);
    4)JScrollPane.setHorizontalScrollBarPolicy(
                   ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
                   JScrollPane.setVerticalScrollBarPolicy(
                   ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    and also we tried to overwrite the setbounds also, but nothing is diplaying..

  • [svn:fx-trunk] 11171: Add overlay property to GroupBase.

    Revision: 11171
    Author:   [email protected]
    Date:     2009-10-26 16:24:13 -0700 (Mon, 26 Oct 2009)
    Log Message:
    Add overlay property to GroupBase. Note, names of class and APIs will change, since it's still in review.
    QE notes: Ready testing, names will change after the APIs review.
    Doc notes: None
    Bugs: None
    Reviewer: Deepa
    Tests run: checkintests, mustella (all gumbo tests)
    Is noteworthy for integration: No
    Modified Paths:
        flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/Accordion.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/containers/ViewStack.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/Container.as
        flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/DataGroup.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/Group.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/GroupBase.as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/layouts/supportClasses/LayoutBase.as
    Added Paths:
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/DisplayPlane .as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/components/supportClasses/OverlayDepth .as
        flex/sdk/trunk/frameworks/projects/spark/src/spark/events/DisplayPlaneObjectExistenceEven t.as

    Thats good news.

  • Subversion client: add subversion property to multiple files fails.

    File browser allows to mark multiple files and then select "add subversion property" in german schown as "Subversion Eigenschaft hinzufügen". This opens a dialog "VCS Operation" showing all selected files with columns name, location and Select. After cklicking on Ok button I get Add Property dialog and can add a property. After confirmation (OK button) only one change is processed! SVN log window shows one action too.
    Any idea how to get it work?
    In comparison: doing multiple Commits by marking multiple files work as expected.
    SQL Developer version is (1.5.4.59.40/Java 1.6.0_13)

    Read this:
    http://forums.adobe.com/message/3068132#3068132

  • How to add a property to BasicPersistence SDK example.

    Hi,
    I see in the BasicPersistence example that it creates a property call BPIData and persists this in the IDML.  I would like to add another property call MyProperty.  Do you know how to add an additional property to the example which is persisted in the IDML, so now it would persist 2 properties? 
    Thanks,
    Dave

    for example:
    javax.jcr.Session session = resourceResolver.adaptTo(Session.class);
    String parentPath = "/content/blah"; // or whatever your parent path is
    String nodetype = "nt:unstructured"; // or whatever other node type you require
    Calendar calendar = Calendar.getInstance(); // or whatever date
    Node node = session.getNode(parentPath).addNode("nodename", nodetype);
    node.setProperty("myproperty", calendar);
    session.save();

  • [svn] 2861: Add 'resizeMode' property to the Group.

    Revision: 2861
    Author: [email protected]
    Date: 2008-08-15 16:52:48 -0700 (Fri, 15 Aug 2008)
    Log Message:
    Add 'resizeMode' property to the Group. Setting this to "Scale" will turn on the 'resize-by-scale' behavior.
    Reviewed by Glenn
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/core/Group.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/LayoutItemUIC.as
    flex/sdk/trunk/frameworks/projects/framework/src/mx/core/UIComponent.as
    Added Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/core/ResizeMode.as

    Hi,
    In this link you can find:  Introduction to the KMC Platform->Collaboration
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/kmc/Knowledge%20Management%20and%20Collaboration%20Developers%20Guide.html
    Patricio.

  • [svn] 2724: Add target property to ILayoutItem

    Revision: 2724
    Author: [email protected]
    Date: 2008-08-04 10:33:18 -0700 (Mon, 04 Aug 2008)
    Log Message:
    Add target property to ILayoutItem
    Make ILayoutItemUIC work with IUIComponent
    Switch Group.GetLayoutItemAt() to return ILayoutItem
    Reviewed by Ryan, Gordon
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/core/Group.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/graphicsClasses/GraphicElement .as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/intf/ILayoutItem.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/BasicLayout.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/HorizontalLayout.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/LayoutItemFDO.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/LayoutItemFactory.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/LayoutItemHelper.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/LayoutItemUIC.as
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/layout/VerticalLayout.as

    Please.... any one can help on this immediately. It is urgent for me.
    Thank you,
    A V G K RAJU

  • [svn] 2695: Add includeInLayout property to GraphicElement.

    Revision: 2695
    Author: [email protected]
    Date: 2008-07-31 13:40:32 -0700 (Thu, 31 Jul 2008)
    Log Message:
    Add includeInLayout property to GraphicElement.
    Reviewed by Ryan.
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/graphicsClasses/GraphicElement .as

  • [svn] 3482: Add resizeMode property to BitmapGraphic.

    Revision: 3482
    Author: [email protected]
    Date: 2008-10-03 16:22:55 -0700 (Fri, 03 Oct 2008)
    Log Message:
    Add resizeMode property to BitmapGraphic. Options are "Normal", "Repeat", "Scale"
    Reviewed by Ely
    Modified Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/BitmapGraphic.as
    Added Paths:
    flex/sdk/trunk/frameworks/projects/flex4/src/flex/graphics/BitmapResizeMode.as

Maybe you are looking for

  • How to fix click of death on External Hard Drive

    PLEASE PLEASE READ ALL!!!!!! My Hard drive is a: G-Drive slim 500GB EHD 5400RPM not sure on warranty. Here is the story. It all started when I was plugging in the HD in my sisters school laptop, when all of a sudden, an error popped up saying "You ne

  • What can I do to edit and add or delete PDF document

    I do not use many functions of acrobat PDF except converting word document into PDF or vice versa. Recently, I have a document in PDF format with pages of writing. What do I if I want to edit the document in PDF format, and to add or to delete certai

  • Form Runtime

    Hi, What is the best way to connect to the database schema automatively when the form is in run time. Example: When you close the form builder or run the form in form runtime, it always prompts you for the database schema. What is the best way to sol

  • Very urgent help in jtsble scroll bar issue

    Hello friends, I am using jtable in scrollpane.I am adding rows in table and wheever we add a row , table will point last added row and scrollbar will go to last point. i used below 2 ways to make i scrollbar down wheever a new row comes. 1.     m_j

  • Photoshop crashes constantly

    This is the fifth time that I have spent HOURS on a picture just to have the tablet go to sleep while I'm doing something like grabbing a soda, answering the phone or using the restroom, and upon awakening the app crashes. I do not have this problem