Showing posts with label netbeans. Show all posts
Showing posts with label netbeans. Show all posts

Wednesday, 27 February 2013

NetBeans IDE 7.3

NetBeans is an integrated development environment (IDE) for developing primarily with Java , but also with other languages, in particular ...

With the latest 7.3 release of NetBeans, Oracle has updated the IDE so developers can more easily build HTML5-based user interfaces for mobile and web applications, with code completion capabilities for HTML, JavaScript, ...

New features include hints and refactorings plus editing FXML and JPQL made easier. The NetBeans IDE 7.3 has arrived this week with advanced HTML5, JavaScript, and CSS development capabilities.
Oracle's NetBeans 7.3 comes with new code writing features for JavaScript, CSS and HTML5

With the release by Oracle of NetBeans 7.3, Project Easel has come to fruition. There is a now support for HTML5, CSS and JavaScript within the framework widely used by Java developers. According Bill Pataky, Oracle vice ...

NetBeans IDE 7.3 introduces support for HTML5 applications and includes significant improvements for editing JavaScript, CSS and HTML files. Other highlights include enhancements to the Java Editor, and improved support for JavaFX, Java EE, PHP, and ...

Tuesday, 6 December 2011

Selecting USE Flags


If you do not need JavaDoc API documentation for NetBeans sources, make sure to disable -doc USE flag. Building documentation for NetBeans sources can take a lot of time.
Since netbeans-6.9-r3, you can turn on support for keychain by enabling keychain. If you enable this, you will be able to benefit from keychain in NetBeans when connecting to ssh protected remote repositories. When you start NetBeans (from menu, from run window or from terminal, does not really matter), keychain will be run and keys that you can optionally specify will be added to ssh-agent and you will be prompted for key passwords if the keys are not managed yet. This is the first and last time NetBeans will ask you for key passwords. To specify keys that you want to add to ssh-agent on NetBeans startup, create file keychain-keys.txt in your userdir (by default ~/.netbeans/6.9/) and put on each line single key that you want to load.
File: ~/.netbeans/6.9/keychain-keys.txt
id_dsa
id_dsa_gentoo


Selecting NetBeans Modules


Before you install NetBeans, you should decide what modules you want to use, or you can simply decide to install all of them. Here is the list of available modules, though some of them do not have to be necesarily available in some NetBeans releases:
File: /usr/portage/profiles/desc/netbeans_modules.desc
# Copyright 2008 Gentoo Foundation.
# Distributed under the terms of the GNU General Public License v2
# $Header: /var/cvsroot/gentoo-x86/profiles/desc/netbeans_modules.desc,v 1.1 2008/11/20 23:43:41 fordfrog Exp $

# This file contains descriptions of NETBEANS_MODULES USE_EXPAND flags.

apisupport - enables apisupport module
cnd - enables C/C++ development support
groovy - enables Groovy and Grails development support
gsf - enables support for web client development
harness - enables harness support
ide - enables NetBeans IDE
identity - enables identity module
j2ee - enables J2EE development support
java - enables Java development support
mobility - enables support for development of mobile applications
nb - enables NetBeans branding
php - enables PHP development support
profiler - enables Java profiler
soa - enables SOA development support
visualweb - enables visual web development support
webcommon - enables javascript libraries and web client tools
websvccommon - enables common support for web services development
xml - enables XML related development support (schema, validation, WSDL, etc.)
By default, emerging NetBeans installs NetBeans with Java development support. If you want to install NetBeans with only Java support, you do not have to adjust the list of modules. Otherwise read on this section.
Because there are dependencies among modules, it may take some time to configure emerge of NetBeans so that it can emerge the package. In case some of the needed modules is not specified, emerge informs you about what module might be missing so you can easily fix it.
Warning: It is important to include nb module otherwise you will build only selected modules and not functional IDE.
Here is an example that you can use in case you want to install all NetBeans modules. Just add this line to your /etc/make.conf:
File: /etc/make.conf
NETBEANS_MODULES="*"

Netbeans


NetBeans is popular open-source and free IDE that runs on Windows, Linux, Mac OS X and Solaris and includes support for several programming and scripting languages. You can find more info about NetBeans at http://netbeans.org. At this moment, the latest version of NetBeans that we have on Gentoo is 6.9. Latest stable version is 6.8. This guide generally applies to Netbeans since version 6.5 and does not describe installation of older versions of NetBeans. Also please note that NetBeans 6.9 is currently masked by ~arch so it is not by default available for those on stable archs. (If you want to install latest NetBeans on stable arch, you can find info in this article too, just read on.)
In Gentoo, NetBeans is currently available for amd64 and x86 systems. If you want NetBeans also for other archs, file a bug at http://bugs.gentoo.org/

Monday, 5 December 2011

Using Verifier in Ant


When deploying the Enterprise JavaBeans, JBoss attempts to verify each bean against the specification to make sure the Bean Developer has fulfilled her contract to implement all the required interfaces. The verifier goes through both session and entity beans making sure the method descriptors do not violate the specification, RMI/IIOP requirements are met, the relevant parts of the deployment descriptor are correct, and so forth.

It is also possible to use the verifier as part of your build process. Using Ant to build your project enables you to verify your Enterprise JavaBeans as you compile them. This removes the extra step of deploying just to verify your ejb-jar file is compliant and deploys correctly in the container. In case of spec violations, you can optionally stop the build process and rework your files to meet the specification requirements. This Howto explains the setup you need to verify your beans early rather than late.

Getting the required files

To use the verifier in Ant you will need two jars copied from the JBoss distribution to your build directory: verifier.jar and metadata.jar. You will find the verifier.jar file in the/dist/bin directory of your JBoss installation, and the metadata.jar in the /dist/external directory.
If you are using the CVS version of JBoss, you can build both of the above mentioned files by executing
src/build> build verifier
in the /src/build directory. This will generate the required packages to the correct directories.

Edit build.xml

A custom verifier task for Ant does not exist at the moment but you can execute the verifier from Ant by creating a new JVM for it using Ant's built in <java> task. For the most up to date information of using the <java> tag, see Ant online documentation.
Below is an example of using the <java> tag to execute the verifier:
<!-- verify the EJBs -->
        <java classname = "org.jboss.verifier.Main" fork="true">
            <classpath refid = "classpath"/>
            <arg value = "${dist.home}/admin.jar"/>
        </java>
      

Saturday, 3 December 2011

Integrating NetBeans/Forte for Java Community Edition


Integrating NetBeans/Forte for Java Community Edition with JBoss for source level debugging

Purpose

This howto is a first pass at illustrating the procedures required to use NetBeans to develop and debug EJBs running within JBoss. It will also discuss how to make the JBoss source available so that debugging can include JBoss code. It is not the purpose of this howto to describe how to develop and debug the JBoss code.
Because Sun's Forte for Java and NetBeans share much of their source code, this howto should be applicable to users in that environment as well.

Install the JBoss Server

For the purpose of this howto, I installed the JBossTomcat release version 2.4.4/3.2.3 into /opt/appserver on my linux box. If you translate the steps into Windows NT/2000 you can also debug JBoss apps using Netbeans there. Download it from http://www.jboss.org and select the binary link from the page. Don't worry about downloading a binary package, when all you want is the source code; the binary package also contains the source code used for building.

Create a NetBeans Project

Start NetBeans, I used NetBeans 3.3 while writing this howto. The first step is to create a new project or open an existing project. You create a new project from the Project -> Project Manager menu selection. This dialog will show a list of your projects like:

Mount the JBoss client jarfiles

This is a bit tedious, though it's not too bad. Once you have opened your project you should go to the explorer window and select the FileSystems tab. Either right click on the FileSystems entry in the explorer window, or choose File -> Mount Filesystem and pick mount jar. Use the browser or type in the path for the following jar files: jboss/lib/ext/jboss-j2ee.jar and jboss/lib/jboss-jdbc_ext.jar. If you are using JBossSX security then you'll also need to add additional jar files jboss/lib/jaas.jar, jboss/lib/jboss-jaas.jar and jboss/lib/ext/jbosssx.jar. If you are using JMS from your client you'll also need to add jboss/lib/ext/jbossmq-client.jar. Once you have added all these jar files a if you don't want them to show in the explorer you can right click on them one by one and from the properties panel select hidden=true.
At this point you need to add any other jar files specific to your app which need to be available to compile your project, e.g. log4j.jar if you are using the Apache logging framework.

Complete your project and build your jar/war files

Now you should be able to mount the directory containing your source code and compile it by right clicking on the root package and selecting compile all.
In order to build a jarfile from which to deploy your EJBs you'll need to add a new jar packager element to your project. Select File -> New and then from the Wizard select Jar Packager -> Jar Contents. This will take you into the Jar Packager wizard. It will allow you to specify the name of the jarfile, select and filter the contents of mounted filesystems for inclusion in the jarfile, and the output directory for the jarfile.
I have never seen POSIX filters before myself, there is good help available within NetBeans. The short version is that a filter to include .class files is \.class$. You could include .class and .xml files with a filter like (\.class$)|(\.xml$). See the online help for more details.
You will need to make sure that you include all required .class files as well as deployment descriptors in the META-INF directory. You right click on the Jar Contents and select "compile" to create the jar file.
After you have built the deployable jar file or war file you can deploy it into your JBoss server. If you want NetBeans to deploy the jar/war file for you then make the output location the jboss/deploy directory and you'll be on your way. Otherwise you'll need to manually copy it from where NetBeans writes it to the jboss/deploy directory.

Setup JBoss for debugging

Since these instructions are not for debugging JBoss so much as an application running in JBoss, at the moment the instructions will start JBoss from the command line and then attach the debugger. At some point in the future we can augment these instructions with instructions to launch JBoss from within NetBeans.
Make the following changes to your run.bat/run.sh file, or copy run.bat/run.sh to a new file debug.bat/debug.sh and paste the text in. This text is the Windows version, the UNIX version should use $env-var instead of %env-var%. Change the command line from:
java %JAXP% -classpath %JBOSS_CLASSPATH% org.jboss.Main ...
to: (as a single command line)
java -Xint -Xdebug -Xnoagent -classpath "%JBOSS_CLASSPATH%" -Xrunjdwp:transport=dt_socket,server=y,address=12999,suspend=n org.jboss.Main %1 %2 %3 %4 %5 %6 %7 %8 %9
The -Xint switch disables hotspot optimizations. This is not strictly necessary, but in my testing with the Win32 JDK 1.3 the JVM seemed more stable with this switch enabled.
You can of course substitute your favorite port for the 12999 in the example.
Once you startup JBoss then you can attach to it from NetBeans to do your debugging. Select the Debug -> Attach menu selection in NetBeans and then the debugger type should be default debugger JPDA. Select the SocketAttach in the connector dropdown and then enter the port number you selected when you edited the debug.bat/debug.sh file. The hostname should default to your local hostname when you select SocketAttach. After you complete filling in the debug "Attach to VM" dialog it should look something like:

Start the JBoss server

Start JBoss using the debug script which you previously created. Deploy the EJBs you'd like to debug. If you want to see your beans being instantiated by the deployer, place breakpoints on the bean constructors (if you specified them) You will not need to have a client running to exercise this functionality.

Sprinkle breakpoints throughout your EJB and or Client Code

Before you can debug, it is necessary to put breakpoints into your code. On the client side you can just open up your source files and toggle breakpoints as in any other Netbeans debugging effort. To put breakpoins into your ejb's is different. You will need to use the loaded classes menus to select the class and method you would like to break on. Once you have hit a break point within the class, and the source code is displayed, then you can add additional breakpoints. This seems to be an artifact of the class loading scheme used by JBoss, and a problem within NetBeans where it puts a breakpoint on the system classloader when you just open the source file and toggle a breakpoint.

Start the Client Test Application

To really debug your beans you will need to start up a client application. The easiest way to do this is either with a command line client, or else with a servlet/JSP client running inside any embedded or otherwise servlet container. One thing though, the timeouts are somewhat short so if you spend too much time in a method within the EJB you may find that transactions are rolled back.

Usefull NetBeans Shortcuts


It’s been several days that I am relying solely on NetBeans for my PHP and Java coding. So far, it’s beyond my wildest expectations – I am totally satisfied with that great IDE. Today, I have searched for shortcut that would allow me to duplicate a given line, and (fortunately!) came by a great post – Top 10 NetBeans IDE Keyboard Shortcuts. Not only I found the line-duplication thing, I discovered several other pearls which due to unavailability in my previous IDEs, I even didn’t consider to look for.
So, I decided to compile my own list of shortcuts that save me a lot of time during code-sessions.
Shift + Esc Toggle Work-space Maximize/Minimize
Like the original post author, I really like to have as much work-space available for code itself as possible. And when I occasionally need to see one of the supplementary panels (like Files, Project, Navigator etc), I rely mostly on short-cuts, w/o toggling back. So, if I need to view some docking panel I hit one of the following:
Ctrl+1 – Project Window
Ctrl+2 – Files Window
Ctrl+3 – Favorite Window
Ctrl+4 – Output Window
Ctrl+5 – Services window
Ctrl+6 – Tasks Window
and when I am done, Ctrl+0 to get me back to editor. Try for yourself, I am pretty sure, you’d be amazed how much time this saves you, while making coding area less cluttered.
Alt+Enter View fix suggestions
NetBeans makes your life a lot easier, its Java code analyzer does a really solid job. Most of errors are filtered even before compilation – should you see the light bulb on the left of your code, you can review fix suggestions by either clicking on it or (time-saver again!) by just hitting Alt+Enter. I personally enjoy this one, as I prefer to see why IDE is complaining w/o releasing my hands of the keyboard.
Ctrl+F12 Navigate to Member
If your class is too big, then Members View in Navigator (Ctrl+7 remember?) might not be the best option. Just hit Ctrl+F12 and you’d be able to navigate more easily, as it has filter that would eliminate non-matching members while you are typing.
Alt+Insert Generate code
That’s one of my favorites – code generators for getters/setters/constructors are just too sexy to ignore. This shortcut makes them even more usefull.
Ctrl+Shift+ArrowDown Duplicate Line
Duplicating lines never been easier :) If you want a new duplicate to be inserted before the current line, use ArrowUp instead of ArrowDown.
Ctrl+W Close Current Window
Firefox honors this short-cut, as well as Konqueror. So, I even configured my console to use this by default. In no time you’d be accustomed to hit this combination instead of Ctrl+F4.
Ctrl+PgUp and Ctrl+PgDn Navigate through Windows (previous/next)
Again, got used to it from Firefox. Makes it a swift to loop through open documents.
Ctrl+P Display method’s arguments
Within method’s braces hit this combination to see what parameters are there. Comes where handy when reviewing the code.
Ctrl+; Add semicolon to the end of the line w/o leaving current cursor position
If you are working on some code line and NetBeans underlines it red (due to [yet] non-existent semicolon at the end of the line) hitting Ctrl + ; (Ctrl + semicolon) is enough to close the statement, while you are still positioned at the very same place on line. First saw this on dzone.com blog, and really liked using it.
Ctrl+K and Ctrl+L Auto complete with previous/next matched word
I use this combination even more often than Ctrl+Space to auto complete. Listing all items with Ctrl+Spacemight be slow, but hitting Ctrl+K is instant. More than often the variable name you are typing is already typed somewhere in the current file, thus matching it with Ctrl+K or Ctrl+L is probably most obvious thing to do.
Ctrl+E Delete current line
Ctrl+Del and Ctrl+BackSpace Delete next/previous word
I generally use Ctrl+BackSpace, but on some occasions Ctrl+Del also proved userful.
That’s more than enough to get you going. In some time, I plan to write more extensive list  of esoteric shortcuts you rarely use, because you rarely know about them.
And what shortcuts save your time?

Netbeans + PHP Type Hinting


Sometimes, especially when dealing with variations of factory pattern, single method (namely factory()) can return objects of different types, so NetBeans is unable to guess the exact type of returned instance and as such cannot auto-complete. Indeed, you can setup return type using phpDoc syntax:
  1. /** 
  2.  * @return Some_Base_Abstract_Class_Name 
  3.  */  
  4. public function factory($adapter)  
but that doesn’t work if returned objects are specifications of more general abstract class (exactly the case with factory).
As it turned out, you can easily resolve this issue – just document your variable with @var, before calling factory() method:
  1. /** 
  2.  * @var Some_Specific_Class $foo 
  3.  */  
  4. $foo = Magic::factory('adapterName');  
  5. $foo-> // and NetBeans opens pop-up list with available attributes and methods  
The good news, you can use this method in any scope – it just works :) I love NetBeans!!
UPD: Well, actually NetBeans seems to be picky of scope – as reported by others (and confirmed by myself).
UPD1: Actually NetBeans handles this quite well, just use vdoc

Saturday, 19 November 2011

MySQL WorkBench

You need MySQL workbench to register on netbeans. As netbeans will by default not have Register MySQL db enabled for you. Configuring that would require the GUI tool for MySQL

Visit MySQL GUI Tools Downloads to download

Thursday, 17 November 2011

Older versions of Java can lead to security threats

Java is well documented. Java was “responsible for between one-third and one-half of all [recent] exploits.” Over the past six month Java was found to be the most common exploit vector in all the cases
Read more about Java and the security threats

Thursday, 10 November 2011

Automatic window lifecycle management


A further major advantage of the NetBeans Window System is that it provides a WindowManager that controls the lifecycle of all the windows defined in the application. The WindowManager notifies allTopComponents about state changes using callback methods, listed as follows:

componentOpened()It is called after the TopComponent has been opened. If multiple TopComponents are opened into the same position (called mode), the NetBeans Window System uses a tabbed container, with one TopComponent per tab. Of all available TopComponents found within a shared tabbed container, only the content of the selected TopComponent is visible.
componentShowing()It notifies the component that its content is now visible. This TopComponent is now either selected or is the only component in a separate container.
componentActivated()It is called after the TopComponent has gained the input focus or has become the selected component.
componentDeactivated()It is called after the TopComponent has lost the input focus.
componentHidden()It notifies the TopComponent that its content is no longer visible.
componentClosed()It is called after the TopComponent has been closed.
Let's illustrate this lifecycle via an example that logs all the callback methods to the output window of NetBeans IDE, which is your development environment on top of the NetBeans Platform.
  1. Create a new NetBeans Platform application and name it WindowSystemExamples.
  2. Add a new module named LifeCycle, with Code Name Base com.netbeansrcp.lifecycle.
  3. Add a TopComponent, with Class Name Prefix prefix LifeCycleDemo, making sure to indicate that it should be automatically opened in the editor area at application startup.
  4. Override the lifecycle methods as follows:
    public void componentOpened() { super.componentOpened(); System.out.println("componentOpened()"); } protected void componentShowing() { super.componentShowing(); System.out.println("componentShowing()"); } protected void componentActivated() { super.componentActivated(); System.out.println("componentActivated()"); } @Override protected void componentDeactivated() { super.componentDeactivated(); System.out.println("componentDeactivated()"); } @Override protected void componentHidden() { super.componentHidden(); System.out.println("componentHidden()"); } @Override public void componentClosed() { super.componentClosed(); System.out.println("componentClosed()"); }
Start the new application. The TopComponent LifeCyleDemoTopComponent is automatically opened at startup. Select the TopComponent and inspect the output in the NetBeans IDE Output Window. You should see the following:
componentOpened() componentShowing() componentActivated()
The TopComponent has passed the first half of its lifecycle and is now activated.
Close the LifeCyleDemoTopComponent and inspect the output again, to understand the second half of the TopComponent lifecycle. You should see the following output:
componentHidden() componentDeactivated() componentClosed()
You have learned that the TopComponent's lifecycle is automatically controlled by the NetBeans Platform. Between the start and the end of the TopComponent's lifecycle are six different states, all managed by the NetBeans Platform, and with notifications sent via callbacks.

Programmatically managing the Window lifecycle

You can manage the lifecycle of a TopComponent programmatically. For this purpose, theTopComponent provides the following methods:
  • open(): Opens the TopComponent
  • requestVisible(): Requests to select to TopComponent
  • requestActive(): Requests to transfer the input focus to the TopComponent
Let's now modify the LifeCycleDemoTopComponent for demonstration purposes.
  1. Add a JButton to the TopComponent, as follows:
  2. Implement an ActionEventListener as follows:
    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.close(); RequestProcessor.getDefault().post(new java.lang.Runnable() { public void run() { java.awt.EventQueue.invokeLater(new java.lang.Runnable() { public void run() { com.netbeansrcp.lifecycle.LifeCycleDemoTopComponent.this.open(); } }); } }, 3000); RequestProcessor.getDefault().post(new java.lang.Runnable() { public void run() { java.awt.EventQueue.invokeLater(new java.lang.Runnable() { public void run() { com.netbeansrcp.lifecycle. LifeCycleDemoTopComponent.this.requestActive(); } }); } }, 6000); }
  3. Restart the application. When you click the button, the LifecycleDemoTopComponent is closed via the close() method, called above in the first line of the code you entered.
The RequestProcessor provides a thread pool. The default instance of this pool lets you execute aRunnable after a short delay, thanks to the post() method. As the TopComponent's lifecycle method should be called from the AWT event thread, you do not call them directly in the run() method, but by posting a new Runnable to the EventQueue, which in the end calls the Window System API methods.
The argument 3000 ensures that the execution of the Runnable is delayed for 3000 ms so that theTopComponent is opened again after 3 s.
After six seconds the second Runnable posted to the EventQueue is executed and requestActive() is called for your LifecycleDemoTopComponent. Your TopComponent is now shown in the foreground, if it had been behind other windows previously.
You have learned how to manage the lifecycle of a TopComponent. Via the example you have seen how to open a TopComponent and make it focusable.

Positioning of windows

The NetBeans Window System divides the available space in the main window into areas that are called "modes". Each mode represents a specific area of the main window, providing a container for windows in a predefined position in the frame. You can add windows, that is, TopComponents, to a mode, either declaratively or programmatically.
A standard layout is provided by the NetBeans Window System, corresponding to the layout of NetBeans IDE. For example, the predefined modes correspond to the names used in the corresponding positions in NetBeans IDE, such as "editor" and "explorer". If needed, you can define your own modes, too. No wizard is provided for this purpose in NetBeans IDE, so you need to create the mode definition files yourself manually.
In the previous section you learned about the layer.xml file. To create a default layout for an application, each TopComponent needs to be declaratively registered within the Windows2 | Modes folder, within a subfolder named after the mode in which the TopComponent should be docked.
To demonstrate declarative registration of TopComponents, edit the layer.xml in the LifeCycle module, changing the folder name Windows2 | Modes | editor to Windows | Modes | rightSlidingSide, as shown in the following code snippet:
layer.xml // <folder name="Windows2"> <folder name="Components"> <file name="LifecycleDemoTopComponent.settings" url="LifecycleDemoTopComponentSettings.xml"/> </folder> <folder name="Modes"> <folder name="rightSlidingSide"> <file name="LifecycleDemoTopComponent.wstcref" url="LifecycleDemoTopComponentWstcref.xml"/> </folder> </folder> </folder> //
Select Clean and Build on the application node in the Projects window, to remove the build folder containing the last used window layout, and start the application again. When the application starts up, notice that the LifecycleDemoTopComponent is not opened in the editor mode. Instead, it is represented by a button on the right sidebar of the application (as shown in the screenshot below). That is therightSlidingSide mode, providing a container for minimized windows.
As you have seen, providing a default layout via declarative registrations of TopComponents is rather easy. You only need to create an entry in the layer.xml for the TopComponent, in a folder with the name of the desired mode, within the Windows2 | Modes folder.
Sometimes declarative registration alone is too static for your business needs. Fortunately, positioning ofTopComponents can also be done programmatically. In the next example, you create a TopComponentthat moves to new modes via a click of a button.
  1. Add to the WindowSystemExamples application a new module named Modes, with the Code Name Base com.netbeansrcp.modes.
  2. Within the module, create a TopComponent called ModesDemo, which is opened when the application starts into the "editor" mode.
Add two JButtons to the TopComponent with the texts Back and Forward, as well as a JLabel with an empty initial text. The TopComponent should look as shown in the following screenshot:
In the Source view, add the following code:
private static final String[] MODES = new String[] { "properties", "commonpalette", "rightSlidingSide", "bottomSlidingSide", "output", "debugger", "navigator", "explorer", "leftSlidingSide", "editor" }; private void changeMode(boolean next) { Mode currentMode = WindowManager.getDefault().findMode(this); String currentModeName = currentMode.getName(); String nextModeName = "editor"; for (int i = 0; i < MODES.length; i++) { String modeName = MODES[i]; if (modeName.equals(currentModeName)) { if (next) { nextModeName = (i + 1 < MODES.length) ? MODES[i + 1] : MODES[0]; } else { nextModeName = (i - 1 >= 0) ? MODES[i - 1] : MODES[MODES.length - 1]; } break; } } Mode nextMode = WindowManager.getDefault().findMode(nextModeName); if (nextMode != null) { this.jLabel1.setText(nextModeName); nextMode.dockInto(this); this.open(); this.requestActive(); } } private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { this.changeMode(true); } private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { this.changeMode(false); }
The static string array contains the names of the most important modes. These modes can also be identified dynamically, by calling WindowManager.getDefault().getModes().
The ActionListener delegates the call to the method changeMode() and gives the desired back/forward direction. This method determines via WindowManager.getDefault ().findMode (this) the mode in which theTopComponent is displayed, as well as the name of the current mode.
The string array is then searched and dockInto(this) is called to dock the TopComponent into a different mode.
How to revert to the default layout?
As the layout of the NetBeans Platform is persisted when the application shuts down, first perform a Clean and Build on the application project. With the removal of the build folder, the layout settings are also deleted, so that the default layout is used when the application starts again.
Using the two buttons, you can let the TopComponent be docked in some of the most commonly used modes (as shown in the screenshot below).
You have programmatically docked a TopComponent into various places within the available modes in the application. In the process, you have learned how TopComponents can be docked dynamically, that is, at runtime, into desired positions. Both the declarative and the programmatic approaches to docking should now be familiar to you.