participate


Swing - Debugging Webstart Applications
<<   Back to Forum  |   Give us Feedback
This topic has 6 replies on 1 page.
camickr
Posts:32,731
Registered: 2/27/98
Debugging Webstart Applications   
Nov 7, 2009 5:34 PM

 
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>

 
AndrewThompson64
Posts:3,837
Registered: 12/28/05
Re: Debugging Webstart Applications   
Nov 7, 2009 6:45 PM (reply 1 of 6)  (In reply to original post )

 
The JNLP file has some elements out of order. I recommend you validate it against a DTD or (better) XSD. I offer both YAX-V and JaNeLA to help validate JNLP launches, though JaNeLA goes a lot further for checking aspects of JNLP based launches.

As far as the immediate debugging goes, go to the advanced tab of the Java Control Panel. Under the Java Console leaf, ensure Show Console is selected. That should result in the console popping open for any applet or JWS app. start-up.
 
DarrylBurke
Posts:15,598
Registered: 7/2/07
Re: Debugging Webstart Applications   
Nov 7, 2009 7:15 PM (reply 2 of 6)  (In reply to original post )

 
When I run from your server, I get only one option pane, but that's not the same GUI you posted here. Are you sure you uploaded the latest build to the server?

Once I build the jar myself (using your code, no change except to introduce a package) and run it from my local disk using this minimally modified jnlp file, I get all 3 option panes.
<jnlp spec="1.0+"
codebase="file:///e:/jnlp"
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="tooltiplistener.ToolTipListenerTest"/>
</jnlp>

db

edit OK I downloaded the jar from your site and now I see what you're saying. the option panes with the "java.awt.Point" messages don't appear under jnlp.

Edited by: DarrylBurke
 
camickr
Posts:32,731
Registered: 2/27/98
Re: Debugging Webstart Applications   
Nov 7, 2009 7:54 PM (reply 3 of 6)  (In reply to #1 )

 
@Darryl,

Thanks, the codebase was the change I needed to test on my local machine.

Yes, the code on the website is messed up with all my attempts to debug the problem so it doesn't show my real problem, which has now been identified as described below.

@Andrew,

I copied the .jnlp file from the Sun tutorials and have used it 8-9 times for various demos on my blog without problem. All I do is a global rename from the last .jnlp file I use.

Thanks for the tip about the Java console thats what I needed to solve the problem.

After starting the console and changing the codebase, the real problem with the code was apparent. I am getting a SecurityAccessControlException. It doesn't like my usage of the MouseInfo.getPointerInfo() method in the ToolTipListener class.

I believe the only solution to this is to sign the jar file. Well, I don't really feel like learning how to do this right now. So I guess the simple solution to my problem will be to not include the Webstart demo when I release the blog entry tomorrow.

Thanks for the help.
 
AndrewThompson64
Posts:3,837
Registered: 12/28/05
Re: Debugging Webstart Applications   
Nov 7, 2009 9:27 PM (reply 4 of 6)  (In reply to #3 )

 
camickr wrote:
...I copied the .jnlp file from the Sun tutorials ..

Do you have an URL for that? (1)

(polite cough) Sun's tutorials do not always have the best information. AFAIR many of the (simple) Swing examples fail to use invokeLater to create & display the GUI, and I recall reading a Sun tech. blog on some new functionality to help with IO try/catch/finally structures that commented that even the Java Tutorial got it wrong.

Sun's tutorials are good overall, but sometimes simplify things to make it to the point faster, and occasionally they 'get it wrong'.

(1) The thing in particular that I noticed, was that the j2se and jar elements are in the wrong order, and I do not recall seeing any Sun example that swapped the order of the elements.

..and have used it 8-9 times for various demos on my blog without problem.

Using which version of JWS on which platform? The thing about invalid JNLP files is that how they are parsed is 'undefined'. Just because that JNLP works in your current Java version, does not mean that it will work in OpenJava JWS, or even the next version of Java from Sun.

Of course, I am not about to imply that just because a JNLP is valid, that there will never be a bug that causes JWS to fail. But I do strongly feel that it is worth validating a JNLP that is involved with a launch that is showing problems of any kind.

Thanks for the tip about the Java console thats what I needed to solve the problem.

You're welcome. Glad you sorted it.

After starting the console and changing the codebase, the real problem with the code was apparent. I am getting a SecurityAccessControlException. It doesn't like my usage of the MouseInfo.getPointerInfo() method in the ToolTipListener class.

I had a brief scan of the codes but nothing security related jumped out at me.

I believe the only solution to this is to sign the jar file.

Yep. Some things can be done with j2ee-application-client-permissions, but for most cases, all-permissions is required. For either of those permission levels, all Jars in the JNLP file must be digitally signed.

..Well, I don't really feel like learning how to do this right now. So I guess the simple solution to my problem will be to not include the Webstart demo when I release the blog entry tomorrow.

If you find the time, check over some of my webstart examples. The FileService demo in particular is signed. The build file and source is available for download.
 
Kleopatra
Posts:464
Registered: 6/16/97
Re: Debugging Webstart Applications   
Nov 8, 2009 3:56 AM (reply 5 of 6)  (In reply to #3 )

 
camickr wrote:
@Darryl,

After starting the console and changing the codebase, the real problem with the code was apparent. I am getting a SecurityAccessControlException. It doesn't like my usage of the MouseInfo.getPointerInfo() method in the ToolTipListener class.

I believe the only solution to this is to sign the jar file. Well, I don't really feel like learning how to do this right now. So I guess the simple solution to my problem will be to not include the Webstart demo when I release the blog entry tomorrow.

or maybe not use the MouseInfo - use comp.getMousePosition()? didn't try but would expect the internal implementation to cushion any permission issues. Simply curious :-)

Jeanette
 
camickr
Posts:32,731
Registered: 2/27/98
Re: Debugging Webstart Applications   
Nov 8, 2009 9:15 AM (reply 6 of 6)  (In reply to #5 )

 
@Andrew

The thing in particular that I noticed, was that the j2se and jar elements are in the wrong order

I changed all the .jnlp files to follow this ordering.

@Jeanette

or maybe not use the MouseInfo - use comp.getMousePosition()?

...banging head on desk!!! Yes, I became aware of this method at the same time you did. For some silly reason I thought it was new for JTable only.

Anyway, I now know:

a) how to debug using the console
b) a little more about Webstart and jnlp files
c) to be more carefull when reading the API

If anyone cares, the end result of this question is the ToolTips and ScrollPanes entry with a working demo.
 
This topic has 6 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 54
  • Guests : 135

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums