Results 1 to 8 of 8
- 03-01-2011, 08:09 PM #1
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
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:
And finally, the OutputFrameView code: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(); } } }
The bug is the following: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"); } // .... }
- 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
- 03-01-2011, 08:29 PM #2
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
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?
- 03-01-2011, 08:39 PM #3
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
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 textLast edited by tylerdurden; 03-01-2011 at 08:46 PM.
- 03-01-2011, 08:52 PM #4
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
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.mp4Last edited by tylerdurden; 03-01-2011 at 08:54 PM.
- 03-01-2011, 10:30 PM #5
Senior Member
- Join Date
- Feb 2011
- Posts
- 118
- Rep Power
- 0
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?
- 03-01-2011, 11:15 PM #6
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
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.
- 03-04-2011, 12:02 AM #7
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
Even clearer example...
Code:
and video of what happens...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(); } }
- 03-04-2011, 12:45 AM #8
Member
- Join Date
- Mar 2011
- Posts
- 6
- Rep Power
- 0
Ok this is a bug:
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.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(); } }
Video to show it.Last edited by tylerdurden; 03-04-2011 at 01:33 AM.
Similar Threads
-
Serialization and Deserialization of multiple objects from single file
By hanx in forum Advanced JavaReplies: 3Last Post: 02-28-2011, 05:09 PM -
Singleton serialization / deserialization
By DerekRaimann in forum New To JavaReplies: 4Last Post: 02-28-2011, 01:38 AM -
Enum singleton serialization and deserialization
By bassfero in forum Advanced JavaReplies: 16Last Post: 09-08-2010, 01:37 PM -
Serialization/Deserialization Error
By andrepezzo in forum Advanced JavaReplies: 2Last Post: 12-16-2008, 05:36 PM -
Serialization/Deserialization Error
By andrepezzo in forum NetworkingReplies: 0Last Post: 12-16-2008, 04:21 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks