<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>diederickdevries.net &#187; netbeans</title>
	<atom:link href="http://www.diederickdevries.net/blog/tag/netbeans/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.diederickdevries.net/blog</link>
	<description>Of penguins and coffee (mostly).</description>
	<lastBuildDate>Fri, 03 Feb 2012 17:08:59 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Java 3d in a NetBeans Platform Application</title>
		<link>http://www.diederickdevries.net/blog/2011/11/12/java-3d-in-a-netbeans-platform-application/</link>
		<comments>http://www.diederickdevries.net/blog/2011/11/12/java-3d-in-a-netbeans-platform-application/#comments</comments>
		<pubDate>Sat, 12 Nov 2011 11:25:31 +0000</pubDate>
		<dc:creator>diederick</dc:creator>
				<category><![CDATA[cool stuff]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[j3d]]></category>
		<category><![CDATA[j3dcore]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[java3d]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.diederickdevries.net/blog/?p=1192</guid>
		<description><![CDATA[If you want an excellent introduction into Java 3D, look no further than here. I was following the tutorial I found there to get started with what looked to me as the perfect way of spending a Friday evening, when, somewhere at the end, it told me that: (&#8230;) it does not mix very well [...]]]></description>
			<content:encoded><![CDATA[<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.diederickdevries.net%2Fblog%2F2011%2F11%2F12%2Fjava-3d-in-a-netbeans-platform-application%2F&amp;title=Java%203d%20in%20a%20NetBeans%20Platform%20Application" id="wpa2a_2"><img src="http://www.diederickdevries.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>If you want an excellent introduction into Java 3D, look no further than <a href="http://www.java3d.org/tutorial.html">here</a>. I was following the tutorial I found there to get started with what looked to me as the perfect way of spending a Friday evening, when, somewhere at the end, it told me that:</p>
<blockquote><p>(&#8230;) <span style="font-family: TIMES; font-size: small;">it does not mix very well with Sun.s swing user interface components. These components are called &#8220;lightweight&#8221; Lightweight components can be hidden by a Canvas3D even if they are supposed to be at the front.</span></p></blockquote>
<p>Obviously, I had been planning on embedding hugely impressive 3D animations into a NetBeans Platform Application, and I was not going to be disappointed, so I fired up NetBeans and did it anyway. Here&#8217;s how.</p>
<p>Preconditions: The j3dcore JAR files are downloaded and unpacked.  You can find them <a href="http://java3d.java.net/binary-builds.html">here</a>. I never trust generic Linux installers, because I have no idea what distro those people had in mind when creating them. So I chose one from the zip binaries and ignored the installers. Select the appropriate one for your machine. Unpack the zip file. There&#8217;s a second zip file inside. Unpack it too. Put the JAR files and the <code>.so</code> file somewhere where you want to keep them.</p>
<p>There appears to exist a NetBeans <a href="http://plugins.netbeans.org/plugin/32144/java-3d">plugin</a> for java-3d, but my NetBeans (7.0.1) didn&#8217;t find it, and at least one user comment indicates massive issues, so I didn&#8217;t bother with it.</p>
<ol>
<li>Create a new Application: File -&gt; New Project. In the Wizard, under Choose Project, select NetBeans Modules -&gt; NetBeans Platform Application and click Next. Enter the name of the application. I called it Test3D. Click Finish.</li>
<li>The j3dcore JAR files have to be wrapped into a Module. Expand the Test3D project node, right click Modules and select Add New. Use j3dcore as your project name and click Next.  Use net.java.j3dcore as the Module&#8217;s code name base.</li>
<li>Right click the j3dcore module node and choose Properties. Under Libraries, click the Wrapped JARs tab and click Add JAR. Navigate to the j3dcore JAR files, select them all (hold shift or ctrl) and click OK.</li>
<li>You now have a library wrapper module, but you lack the shared object file that will allow them to use you graphics adapter. In Test3D, expand the Important Files node. Open the Project Properties file, and add the following line:
<p><code>run.args.extra=-J-Djava.library.path=&lt;the path to the location of your .so file&gt;</code></p>
<p>Do not include the name of the file itself. Be sure to add this to the Project Properties file of your main project, Test3D, and not the wrapper module. It has its own Project Properties file.</li>
<li>Add a new module that creates and displays your 3D scene. Right click Modules under Test3D and click Add New. Enter a name. I chose Universe. Enter your code name base and click Finish.</li>
<li>Add a new TopComponent. Right click the Universe node and click New -&gt; Other. In the New File wizard, select Module Development -&gt; Window. Select Editor as Window Placement and select Open on Application Start. Click Next. Enter UniverseTopComponent after Class Name Prefix and click Finish.</li>
<li>Open UniverseTopComponent. In the Design View, add a JPanel that fully covers the TopComponent. Right click it, select Change Variable Name and enter myUniverse. Right click it again, choose Set Layout -&gt; Border Layout.</li>
<li>Switch to the Source Editor, and change the constructor into this:</li>
</ol>
<blockquote><blockquote>
<pre class="brush: java">
    public UniverseTopComponent() {

        initComponents();
        setName(NbBundle.getMessage(UniverseTopComponent.class,
                &quot;CTL_UniverseTopComponent&quot;));
        setToolTipText(NbBundle.getMessage(UniverseTopComponent.class,
                &quot;HINT_UniverseTopComponent&quot;));

        GraphicsConfiguration config = SimpleUniverse.getPreferredConfiguration();
        Canvas3D canvas = new Canvas3D(config);
        myUniverse.add(canvas, BorderLayout.CENTER);        

        BranchGroup group = new BranchGroup();

        Sphere sphere = new Sphere(0.2f);
        group.addChild(sphere);

        Color3f lightColor = new Color3f(1.8f, 0.1f, 0.1f);
        BoundingSphere bounds =
                new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0);

        Vector3f lightDirection = new Vector3f(4.0f, -7.0f, -12.0f);
        DirectionalLight light = new DirectionalLight(lightColor, lightDirection);
        light.setInfluencingBounds(bounds);
        group.addChild(light);

        SimpleUniverse universe = new SimpleUniverse(canvas);
        universe.getViewingPlatform().setNominalViewingTransform();
        universe.addBranchGraph(group);

    }
</pre>
</blockquote>
</blockquote>
<ol start="9">
<li>Right click the editor window and select Fix Imports from the popup menu. Then build and run the project. Your output should look like this:</li>
</ol>
<div id="attachment_1200" class="wp-caption aligncenter" style="width: 548px"><a href="http://www.diederickdevries.net/blog/2011/11/12/java-3d-in-a-netbeans-platform-application/test3d/" rel="attachment wp-att-1200"><img class="size-full wp-image-1200" title="test3d" src="http://www.diederickdevries.net/blog/wp-content/uploads/2011/11/test3d.png" alt="Screenshot Test3d Example Application" width="538" height="495" /></a><p class="wp-caption-text">Test3D with Universe Window</p></div>
<p>Conclusion: it is possible to embed a Java 3D scene into a NetBeans Platform Application.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.diederickdevries.net/blog/2011/11/12/java-3d-in-a-netbeans-platform-application/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Native look and feel for Swing under Linux</title>
		<link>http://www.diederickdevries.net/blog/2011/04/19/native-look-and-feel-for-swing-under-linux/</link>
		<comments>http://www.diederickdevries.net/blog/2011/04/19/native-look-and-feel-for-swing-under-linux/#comments</comments>
		<pubDate>Tue, 19 Apr 2011 18:41:30 +0000</pubDate>
		<dc:creator>diederick</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[gtk]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[kde]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[netbeans]]></category>
		<category><![CDATA[qt4]]></category>
		<category><![CDATA[swing]]></category>

		<guid isPermaLink="false">http://www.diederickdevries.net/blog/?p=893</guid>
		<description><![CDATA[This one is not really an eye-opener, but I use this blog to record and archive stuff I find out at some point, so here&#8217;s a post about getting NetBeans Platform Applications use GTK instead of Metal. Since the Swing Application Framework (SAF) has been deprecated and developing NetBeans Platform Applications (NPA) is the new [...]]]></description>
			<content:encoded><![CDATA[<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.diederickdevries.net%2Fblog%2F2011%2F04%2F19%2Fnative-look-and-feel-for-swing-under-linux%2F&amp;title=Native%20look%20and%20feel%20for%20Swing%20under%20Linux" id="wpa2a_4"><img src="http://www.diederickdevries.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>This one is not really an eye-opener, but I use this blog to record and archive stuff I find out at some point, so here&#8217;s a post about getting NetBeans Platform Applications use GTK instead of Metal.</p>
<p>Since the Swing Application Framework (SAF) has been <a href="http://netbeans.org/kb/68/java/gui-saf.html">deprecated</a> and developing <a href="http://netbeans.org/features/platform/">NetBeans Platform Applications</a> (NPA) is the new and better way to do these things, I&#8217;ve bought a good <a href="http://www.packtpub.com/netbeans-platform-6-9-developers-guide/book">book</a> on the subject, and am quite satisfied with the way Java desktop applications are to be developed these days.</p>
<p>However, under Linux, Swing applications default to the ugly Metal widget set:</p>
<div id="attachment_894" class="wp-caption aligncenter" style="width: 310px"><a rel="attachment wp-att-894" href="http://www.diederickdevries.net/blog/2011/04/19/native-look-and-feel-for-swing-under-linux/metal/"><img class="size-medium wp-image-894" title="metal" src="http://www.diederickdevries.net/blog/wp-content/uploads/2011/04/metal-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">Metal widget set. Click to zoom.</p></div>
<p style="text-align: center;">&nbsp;</p>
<p>On the command line and using SAF it is in fact pretty <a title="QT4 look and feel for Swing" href="http://www.diederickdevries.net/blog/2009/04/29/qt4-look-and-feel-for-swing/">easy</a> to make Swing use the GTK widgets. This way Java applications get a native look and feel under Linux. With NPA however, there is no right place to insert a few lines of code to do this at startup.</p>
<p>To make NetBeans itself use the GTK widgets, I always start the IDE like this:</p>
<pre># netbeans --laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel</pre>
<p>Since NetBeans is itself an NPA,  I figured the trick would be to specify this option somewhere in the application&#8217;s configuration. I googled around a bit and found the answer <a href="http://wiki.netbeans.org/DevFaqPlatformRuntimeProperties">here</a>. The trick is to add a single line to the <code>project.properties</code> file, which can be found inside the Important Files folder within the NPA project. That line is:</p>
<pre>run.args.extra=--laf com.sun.java.swing.plaf.gtk.GTKLookAndFeel</pre>
<p>And now, under KDE4, my application looks like this:</p>
<div id="attachment_895" class="wp-caption aligncenter" style="width: 310px"><a rel="attachment wp-att-895" href="http://www.diederickdevries.net/blog/2011/04/19/native-look-and-feel-for-swing-under-linux/gtk/"><img class="size-medium wp-image-895" title="gtk" src="http://www.diederickdevries.net/blog/wp-content/uploads/2011/04/gtk-300x225.png" alt="" width="300" height="225" /></a><p class="wp-caption-text">GTK widget set. Click to zoom.</p></div>
<p style="text-align: center;">&nbsp;</p>
<p>Not exactly a KDE4 look-and-feel, but I have lots of applications (Gimp, GQView,  LibreOffice) that use GTK so it still looks native on my desktop, and GTK is a lot prettier than Metal.</p>
<p>Now why it is a good idea to write desktop applications instead of web applications, especially in Java, is something that Geertjan Wielenga <a href="http://java.dzone.com/why-desktop-not-webapp">talks</a> about on his blog. Well worth the read.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.diederickdevries.net/blog/2011/04/19/native-look-and-feel-for-swing-under-linux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Deploying EJB3 In Action code examples in NetBeans</title>
		<link>http://www.diederickdevries.net/blog/2011/03/25/deploying-ejb3-in-action-code-examples-in-netbeans-2/</link>
		<comments>http://www.diederickdevries.net/blog/2011/03/25/deploying-ejb3-in-action-code-examples-in-netbeans-2/#comments</comments>
		<pubDate>Fri, 25 Mar 2011 08:34:08 +0000</pubDate>
		<dc:creator>diederick</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[ejb3]]></category>
		<category><![CDATA[glassfish]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.diederickdevries.net/blog/?p=569</guid>
		<description><![CDATA[I&#8217;m currently learning Enterprise Java Beans 3 using Debu Panda et al.&#8217;s book EJB3 in Action. The material is not very hard but there&#8217;s lots of stuff to memorize, and the best way to do that is by running the code examples and trying to change it (and break it). The easiest way to do [...]]]></description>
			<content:encoded><![CDATA[<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.diederickdevries.net%2Fblog%2F2011%2F03%2F25%2Fdeploying-ejb3-in-action-code-examples-in-netbeans-2%2F&amp;title=Deploying%20EJB3%20In%20Action%20code%20examples%20in%20NetBeans" id="wpa2a_6"><img src="http://www.diederickdevries.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>I&#8217;m currently learning <a href="http://www.oracle.com/technetwork/java/docs-135218.html">Enterprise Java Beans 3</a> using Debu Panda et al.&#8217;s book<a href="http://www.manning.com/panda/"> EJB3 in Action</a>. The material is not very hard but there&#8217;s lots of stuff to memorize, and the best way to do that is by running the code examples and trying to change it (and break it). The easiest way to do that is by using an IDE, but the book isn&#8217;t very  helpful in that area, and I didn&#8217;t find it really transparent or straightforward, so here&#8217;s a write up of what I did to make the code examples of the first chapter work in <a href="http://netbeans.org/">NetBeans</a>.</p>
<p>You&#8217;ll need a NetBeans installation with most of the trimmings for this to work. Make sure GlassFish Server 3 and JavaDB are working.</p>
<p>The first chapter is about a simple <a href="http://en.wikipedia.org/wiki/Hello_world_program">Hello World</a> application. To deploy it, we need an EJB3 module and a Web Application Module. The latter will be the client, replacing the client application provided by the book.</p>
<ol>
<li>In NetBeans, create a new project: Java EE -&gt; Enterprise Application (click Next).</li>
<li>Enter <code>HelloUser</code> as project name and click Next.</li>
<li>Click Enable Context and Dependency Injection and click Finish.</li>
<li>Download and unzip the example sources.</li>
<li>Within the newly created directory, locate the directory <code>glassfish/chapter1/src/ejb/bean/ejb3inaction</code>, and copy it to <code>HelloUser/HelloUser-ejb/src/java/</code> within your NetBeans project directory.</li>
<li>From the example sources directory,  locate the directory <code>glassfish/chapter1/src/ejb/client/ejb3inaction</code>, and copy it to <code>HelloUser/HelloUser-war/src/java/</code> within your NetBeans project directory.</li>
</ol>
<p>The client class provided by the book is a very simple illustration of what has been explained so far:</p>
<pre class="brush: java">
package ejb3inaction.buslogic;

import ejb3inaction.example.HelloUser;

import javax.ejb.EJB;

public class HelloUserClient {

    @EJB
    private static HelloUser helloUser;

    public static void main(String[] args) {
        helloUser.sayHello(&quot;Curious George&quot;);
        System.out.println(&quot;Invoked EJB successfully .. see server console for output&quot;);
    }
}
</pre>
<p>This is not something that I could run from inside NetBeans, so I wrote a <a href="http://www.novocode.com/doc/servlet-essentials/">servlet</a> that contains the same code.</p>
<ol>
<li>In the Projects frame, expand HelloUser-war -> Source Packages -> ejb3inaction.example. This package was created when we copied the files to HelloUser-war, back in step 6.</li>
<li>Right click the package node and click New Servlet&#8230;</li>
<li>Use <code>HelloUserServlet</code> as class name and select Add information to deployment descriptor (web.xml). Click Finish.</li>
<li>Replace everything between the import statements and the HttpServlet methods (they&#8217;re folded) with the following:</li>
</ol>
<pre class="brush: java">
import javax.ejb.EJB;

public class HelloUserServlet extends HttpServlet {

    @EJB
    private HelloUser bean;

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType(&quot;text/html;charset=UTF-8&quot;);

        bean.sayHello(&quot;Curious George&quot;);

        PrintWriter out = response.getWriter();
        try {
            out.println(&quot;&lt;html&gt;&quot;);
            out.println(&quot;&lt;head&gt;&quot;);
            out.println(&quot;&lt;title&gt;Servlet HelloUserServlet&lt;/title&gt;&quot;);
            out.println(&quot;&lt;/head&gt;&quot;);
            out.println(&quot;&lt;body&gt;&quot;);
            out.println(&quot;&lt;p&gt;Invoked EJB successfully .. see server console for output&lt;/p&gt;&quot;);
            out.println(&quot;&lt;/body&gt;&quot;);
            out.println(&quot;&lt;/html&gt;&quot;);
        } finally {
            out.close();
        }
    } 
</pre>
<p>As you can see, it is very easy to create a servlet that does what the main method in the client class from the book does, by simply copying a few lines and removing a few unneeded ones from the default servlet created by NetBeans.</p>
<p>When you run the project, your web browser will come up but you won&#8217;t see the output yet. Direct it to <code>http://localhost:8080/HelloUser-war/HelloUserServlet</code>. You should see a single line of text. In NetBeans, go to the output window and select the GlassFish Server 3 tab. There should be a line starting with the word <code>INFO</code>, followed by the text from <code>HelloUserBean.sayHello()</code>.</p>
<p>Now let&#8217;s see if this approach will work equally well for the rest of the examples in the book.</p>

]]></content:encoded>
			<wfw:commentRss>http://www.diederickdevries.net/blog/2011/03/25/deploying-ejb3-in-action-code-examples-in-netbeans-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Netbeans ignores class (+ solution)</title>
		<link>http://www.diederickdevries.net/blog/2010/03/03/netbeans-ignores-class-solution/</link>
		<comments>http://www.diederickdevries.net/blog/2010/03/03/netbeans-ignores-class-solution/#comments</comments>
		<pubDate>Wed, 03 Mar 2010 19:08:22 +0000</pubDate>
		<dc:creator>diederick</dc:creator>
				<category><![CDATA[howto]]></category>
		<category><![CDATA[tech]]></category>
		<category><![CDATA[java]]></category>
		<category><![CDATA[netbeans]]></category>

		<guid isPermaLink="false">http://www.diederickdevries.net/blog/?p=233</guid>
		<description><![CDATA[The weirdest thing happened while I was programming with my favorite IDE, Netbeans 6.8, today. When I work on big applications, I usually split them in two or three projects (usually model, view, controller). Then I import the projects in the main application project. At some point Netbeans suddenly told me it couldn&#8217;t find a [...]]]></description>
			<content:encoded><![CDATA[<p><a class="a2a_dd a2a_target addtoany_share_save" href="http://www.addtoany.com/share_save#url=http%3A%2F%2Fwww.diederickdevries.net%2Fblog%2F2010%2F03%2F03%2Fnetbeans-ignores-class-solution%2F&amp;title=Netbeans%20ignores%20class%20%28%2B%20solution%29" id="wpa2a_8"><img src="http://www.diederickdevries.net/blog/wp-content/plugins/add-to-any/share_save_171_16.png" width="171" height="16" alt="Share"/></a></p><p>The weirdest thing happened while I was programming with my favorite IDE, <a href="http://netbeans.org/">Netbeans</a> 6.8, today. When I work on big applications, I usually split them in two or three projects (usually model, view, controller). Then I import the projects in the main application project. At some point Netbeans suddenly told me it couldn&#8217;t find a class in an imported project to which I referred, even though nothing was wrong with it, and everything compiled perfectly using Ant. Netbeans however insisted the class wasn&#8217;t there and produced error messages and enough red warning lines to make it unworkable.</p>
<p>I googled around a bit, but found nothing. So before trying to find the actual problem, I made a copy of the class that Netbeans couldn&#8217;t find, deleted the old one, and renamed the copy to the original. And then the problem was gone.</p>
<p>What gives?</p>

]]></content:encoded>
			<wfw:commentRss>http://www.diederickdevries.net/blog/2010/03/03/netbeans-ignores-class-solution/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

