Results 1 to 8 of 8
  1. #1
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default setTooltipText broken after serialization/deserialization

    Hello everyone. I've decided to seek help as this is driving me crazy.
    Here is the code:

    The background loader to load a Player from file. Player obviously implements serializable (I removed some extra try catches for readability:

    Java Code:
    private class LoadPlayerTask extends org.jdesktop.application.Task<Object, Void> {
        private FileContents fileContents = null;
        
        LoadPlayerTask(org.jdesktop.application.Application app) {
            super(app);
            FileOpenService fos = null;
            fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
            this.fileContents = fos.openFileDialog(null, null);
        }
    
        @Override protected Player doInBackground() {
            ObjectInputStream ois = null;
            try {
                ois = new ObjectInputStream(this.fileContents.getInputStream());
                Object o = ois.readObject();
                Player p = (Player)o;
                return p;
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                if(ois!=null){
                    try {
                        ois.close();
                    } catch (IOException ex) {}
                }
            }
            return null;
        }
            
        @Override protected void succeeded(Object result) {
            try {
                if (this.get() != null) {
                    Player p = (Player)this.get();
                    OutputFrameView outputFrame = new OutputFrameView();
                    outputFrame.setVisible(true);
                    outputFrame.setSlotIconAndTooltip(p);
                    outputFrame.setComputationResult(p);
                } else {
                    JOptionPane.showMessageDialog(null,
                        "Error loading the selected Player.",
                        "Error",
                        JOptionPane.ERROR_MESSAGE);
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    }
    And finally, the OutputFrameView code:

    Java Code:
    private void setSlotIconAndTooltip(GearSlots gearSlot, Item item){
        // assign a value to imageIcon and borderIcon ...
        if(gearSlot.compareTo(WoWConstants.GearSlots.HEAD)==0 && item.getItemId()!=-1){
            this.headIcon.setIcon(imageIcon);
            this.headBorderIcon.setIcon(borderIcon);
            this.headIcon.setToolTipText("Lightning Flash Pendant");
        }
        // ....
    }
    The bug is the following:
    • this.headIcon.setToolTipText("Lightning Flash Pendant"); works
    • this.headIcon.setToolTipText("<html><body>Lightnin g Flash Pendant</body></html>"); does NOT work


    Basically, setting html tooltips does not work anymore after a deserialization took place...

    I'm quite lost, and I hope that you guys can help me.

    Rob

  2. #2
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    That doesn't make any sense. Does setting an HTML tooltip on the icon BEFORE it's serialized & deserialized work? In other words, is it just an HTML issue?

  3. #3
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    I'll make you a youtube video, it's probably better than me explaining it. brb :)

    Meanwhile to reply to your question. The setTooltipText behaves the following way:

    1) if I do not do any serialization/deserialization, it works with normal text and html text
    2) if I do a serialization/deserialization before calling any setTooltipText, it no longer works if the passed string is in html, but it does work if it is plain text
    Last edited by tylerdurden; 03-01-2011 at 09:46 PM.

  4. #4
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    Here is the video that shows how, if I deserialize an object before ever calling a setTooltipText with html, the method won't work anymore. On the other hand, if I call the method and then deserialize, it all works fine.

    YouTube - tooltipBug.mp4
    Last edited by tylerdurden; 03-01-2011 at 09:54 PM.

  5. #5
    NRitH is offline Senior Member
    Join Date
    Feb 2011
    Posts
    118
    Rep Power
    0

    Default

    LOL--that was entertaining. I see what you mean, but I have no idea why it's doing that. Have you verified that the tooltip fields really are being serialized out?

  6. #6
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    Yes I have, a System.out is printing the proper String (the html String) that should be passed to setTooltipText.

    Note that even by calling setTooltipText("<html><body>my own static html</body></html>"); the bug persists. Calling setTooltipText("my own static html"); however, works fine.

  7. #7
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    Even clearer example...

    Code:

    Java Code:
    package varioustests;
    
    import java.awt.*;
    import java.io.*;
    import javax.jnlp.*;
    import javax.swing.*;
    import wowgearoptimizer.model.Player;
    import wowgearoptimizer.wowconstants.WoWConstants.GearSlots;
    
    public class MyToolTipTest extends JFrame {
    
        public static int positionOffset = 0;
    
        public MyToolTipTest (String id) {
            setTitle("Tool Tip Test: ");
            JButton button = new JButton ("This is a button with tool tip text: ");
            getContentPane().add(button);
            button.setToolTipText(id);
            getContentPane().setLayout(new FlowLayout(FlowLayout.CENTER));
            pack();
            setVisible(true);
            this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
            positionWindow();
        }
    
        public void positionWindow (){
            Point position = new Point(positionOffset, positionOffset);
            positionOffset += 100;
            setLocation (position);
        }
    
        static void ThisWorks(){
            try {
                MyToolTipTest toolTipTest1 = new MyToolTipTest("<html><body>tooltip con html</body></html>");
                Thread.sleep(6000L);
                FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
                FileContents fileContents = fos.openFileDialog(null, null);
                ObjectInputStream ois2 = new ObjectInputStream(fileContents.getInputStream());
                Player player2  = (Player) ois2.readObject();
                MyToolTipTest toolTipTest2 = new MyToolTipTest(player2.getItemForGearSlot(GearSlots.CHEST).getCurrentTooltip());
                MyToolTipTest toolTipTest3 = new MyToolTipTest("tooltip senza html");
                MyToolTipTest toolTipTest4 = new MyToolTipTest("<html><body>tooltip con html</body></html>");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        static void ThisDoesntWork(){
            try {
                FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
                FileContents fileContents = fos.openFileDialog(null, null);
                ObjectInputStream ois2 = new ObjectInputStream(fileContents.getInputStream());
                Player player2  = (Player) ois2.readObject();
                MyToolTipTest toolTipTest1 = new MyToolTipTest(player2.getItemForGearSlot(GearSlots.CHEST).getCurrentTooltip());
                MyToolTipTest toolTipTest2 = new MyToolTipTest("tooltip senza html");
                MyToolTipTest toolTipTest3 = new MyToolTipTest("<html><body>tooltip con html</body></html>");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    
        static public void main(String args[]){
            //ThisWorks();
            ThisDoesntWork();
        }
    }
    and video of what happens...

  8. #8
    tylerdurden is offline Member
    Join Date
    Mar 2011
    Posts
    6
    Rep Power
    0

    Default

    Ok this is a bug:

    Java Code:
        static void ThisAlsoWorks(){
            try {
                String message = "<html><body>This is my serialized object</body></html>";
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                ObjectOutputStream oos = new ObjectOutputStream(baos);
                oos.writeObject(message);
                ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
                ObjectInputStream oins = new ObjectInputStream(bais);
                Object o = oins.readObject();
                MyToolTipTest2 toolTipTest = new MyToolTipTest2(message);
                Thread.sleep(5000L);
                FileOpenService fos = (FileOpenService)ServiceManager.lookup("javax.jnlp.FileOpenService");
                FileContents fileContents = fos.openFileDialog(null, null);
                ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
                ObjectOutputStream oos2 = new ObjectOutputStream(baos2);
                oos2.writeObject(message);
                ByteArrayInputStream bais2 = new ByteArrayInputStream(baos2.toByteArray());
                ObjectInputStream oins2 = new ObjectInputStream(bais2);
                Object o2 = oins2.readObject();
                MyToolTipTest2 toolTipTest2 = new MyToolTipTest2(message);
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    If you mousehover the first frame before the thread.sleep ends, the tooltip shows up, the filechooser pops up, you choose a random file since it won't do anything with it, the new frame pops up, and both have their html tooltips working. However, if you relaunch it and you do not mousehover the first frame to see the tooltip before the sleep ends and the filechooser pops up, the tooltips won't ever show up anymore on either frame.

    Video to show it.
    Last edited by tylerdurden; 03-04-2011 at 02:33 AM.

Similar Threads

  1. Replies: 3
    Last Post: 02-28-2011, 06:09 PM
  2. Singleton serialization / deserialization
    By DerekRaimann in forum New To Java
    Replies: 4
    Last Post: 02-28-2011, 02:38 AM
  3. Enum singleton serialization and deserialization
    By bassfero in forum Advanced Java
    Replies: 16
    Last Post: 09-08-2010, 02:37 PM
  4. Serialization/Deserialization Error
    By andrepezzo in forum Advanced Java
    Replies: 2
    Last Post: 12-16-2008, 06:36 PM
  5. Serialization/Deserialization Error
    By andrepezzo in forum Networking
    Replies: 0
    Last Post: 12-16-2008, 05:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •