I can't figure out how to debug a Webstart application. Here are the steps I go through:
1) Compile ToolTipListenerTest.java
2) Create a jar file using the following command:
jar cfev ToolTipListener.jar ToolTipListenerTest ToolTipListener*.class
3) Test the jar file using:
java -jar ToolTipListener.jar
Click on one of the listener radio buttons and 3 JOptionPanes will appear. This is good.
4) Try to test using a .jnlp file:
javaws ToolTipListener.jnlp
Click on one of the listener radio buttons and only 1 JOptionPane appears. This is bad as I expect 3 to appear like above test. I can't figure out what is happening or how to further debug the code. Any hints.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.awt.event.MouseEvent;
import java.awt.event.AdjustmentListener;
import java.awt.event.AdjustmentEvent;
import javax.swing.ToolTipManager;
public class ToolTipListener
implements ComponentListener, MouseWheelListener, AdjustmentListener
{
/**
* Create a mouseMoved event to pass to the ToolTipManager.
*/
private void phantomMouseMoved(Component component)
{
// Determine mouse location relative to the component
Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
SwingUtilities.convertPointFromScreen(mouseLocation, component);
Dimension size = component.getSize();
Rectangle componentBounds = new Rectangle(0, 0, size.width, size.height);
// Mouse is in the bounds of the component, generate phantom
// mouseMoved event for the ToolTipManager
if (componentBounds.contains(mouseLocation))
{
MouseEvent phantom = new MouseEvent(
component,
MouseEvent.MOUSE_MOVED,
System.currentTimeMillis(),
0,
mouseLocation.x,
mouseLocation.y,
0,
false);
ToolTipManager.sharedInstance().mouseMoved(phantom);
}
}
// Implement ComponentListener
public void componentMoved(ComponentEvent e)
{
Component component = e.getComponent();
phantomMouseMoved( component );
}
public void componentResized(ComponentEvent e)
{
Component component = e.getComponent();
phantomMouseMoved( component );
}
public void componentHidden(ComponentEvent e) {}
public void componentShown(ComponentEvent e) {}
// Implement MouseWheelListener
public void mouseWheelMoved(MouseWheelEvent e)
{
JScrollPane scrollPane = (JScrollPane)e.getSource();
Component component = scrollPane.getViewport().getView();
phantomMouseMoved( component );
}
// Implement AdjustmentListener
public void adjustmentValueChanged(AdjustmentEvent e)
{
JScrollBar scrollBar = (JScrollBar)e.getSource();
JScrollPane scrollPane = (JScrollPane)scrollBar.getParent();
Component component = scrollPane.getViewport().getView();
phantomMouseMoved( component );
}
}
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.net.*;
import javax.swing.*;
import javax.swing.border.*;
import javax.swing.event.*;
public class ToolTipListenerTest extends JPanel
implements ActionListener
{
private JRadioButton noListener;
private JRadioButton mouseWheelListener;
private ToolTipListener listener;
private JTable table;
private JScrollPane scrollPane;
ToolTipListenerTest()
{
setLayout( new BoxLayout(this,BoxLayout.X_AXIS) );
setBorder( new EmptyBorder(10, 10, 10, 10) );
JComponent right = createRightPanel();
JComponent left = createLeftPanel();
add(left);
add( Box.createHorizontalStrut(10) );
add(right);
}
public JComponent createLeftPanel()
{
table = new JTable(50, 50)
{
public String getToolTipText( MouseEvent e )
{
int row = rowAtPoint( e.getPoint() );
int column = columnAtPoint( e.getPoint() );
return "(" + row+ "," + column + ")";
}
};
table.setAutoResizeMode( JTable.AUTO_RESIZE_OFF );
scrollPane = new JScrollPane( table );
scrollPane.setPreferredSize( new Dimension(300, 240) );
scrollPane.getViewport().getView().requestFocusInWindow();
listener = new ToolTipListener();
return scrollPane;
}
public JPanel createRightPanel()
{
noListener = new JRadioButton("No Listener");
mouseWheelListener = new JRadioButton("MouseWheel Listener");
noListener.setSelected( true );
ButtonGroup bg1 = new ButtonGroup();
bg1.add( noListener );
bg1.add( mouseWheelListener );
JPanel p1 = new JPanel( new GridLayout(0, 1) );
p1.setBorder( new TitledBorder("Select Listener to Use") );
p1.add( noListener );
p1.add( mouseWheelListener );
noListener.addActionListener(this);
mouseWheelListener.addActionListener(this);
return p1;
}
public void actionPerformed(ActionEvent e)
{
JOptionPane.showMessageDialog(null, "Action Time");
scrollPane.removeMouseWheelListener(listener);
if (mouseWheelListener.isSelected())
{
scrollPane.addMouseWheelListener(listener);
JOptionPane.showMessageDialog(null, "MouseWheel");
}
if (noListener.isSelected())
{
JOptionPane.showMessageDialog(null, "noListener");
}
JOptionPane.showMessageDialog(null, "Action Time Finished");
}
public static void main(String[] args)
{
SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}
public static void createAndShowGUI()
{
JFrame.setDefaultLookAndFeelDecorated(true);
JFrame frame = new JFrame("ToolTip Listener");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add( new ToolTipListenerTest() );
frame.setSize(480, 240);
// frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Create ToolTipListener.jnlp from the following:
<?xml version="1.0" encoding="utf-8"?>
<!-- JNLP File for ToolTipListener -->
<jnlp spec="1.0+"
codebase="http://www.camick.com/java/webstart/"
href="ToolTipListener.jnlp">
<information>
<title>ToolTipListener Test</title>
<vendor>Tips4Java</vendor>
<description>ToolTipListener Test</description>
<homepage href="http://tips4java.wordpress.com/"/>
<description kind="short">Test showing usage of the ToolTipListener</description>
<offline-allowed/>
</information>
<resources>
<jar href="ToolTipListener.jar"/>
<j2se version="1.6+"/>
</resources>
<application-desc main-class="ToolTipListenerTest"/>
</jnlp>