Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Lingen on the NetBeans Platform

DZone's Guide to

Lingen on the NetBeans Platform

· Java Zone
Free Resource

Try Okta to add social login, MFA, and OpenID Connect support to your Java app in minutes. Create a free developer account today and never build auth again.

A group of students at the Fachhochschule (technical college) Osnabrück in Lingen, Germany, are currently taking a NetBeans Platform course. We're using NetBeans IDE 7.0 Beta 2 and so far, as far as I am aware, there have been no problems (just much much faster than before, plus nice TopComponent annotations, hurray) that have arisen as a result of using this beta release.

The day started with an overview of what NetBeans is, where it comes from, and what the main features of the NetBeans Platform are. Then we deep dived into the module system. Dream team member Aljoscha Rittner is delivering the course together with me, he's currently introducing the class to the window system.

Here's a snapshot:

We've created a few small applications so far, such as this pluggable text editor. Each of the tools shown in the combobox below comes from a different plugin, while the window shown below doesn't know anything about them. Instead, the Lookup.getDefault construction is used to load implementations from the META-INF/services folder:

The interesting code, in the constructor of the window:

final DefaultComboBoxModel dcbm = new DefaultComboBoxModel();

Collection<? extends WordFilterInterface> allFilters = Lookup.getDefault().lookupAll(WordFilterInterface.class);

for (WordFilterInterface filter : allFilters) {
dcbm.addElement(filter);
}

jButton1.addActionListener(new ActionListener() {

@Override
public void actionPerformed(ActionEvent e) {

String myPlainText = jTextField1.getText();

WordFilterInterface wfi = (WordFilterInterface) dcbm.getSelectedItem();

String myProcessedText = wfi.process(myPlainText);

jTextArea1.setText(myProcessedText);

}

});

jComboBox1.setModel(dcbm);

The question you might have is how, if the filter is added to the combo box, is a string displayed in it? Well, the combo box has a default renderer that uses the toString() method of the object it displays to create the label displayed within it:

@ServiceProvider(position=10,service=WordFilterInterface.class)
public class LowercaseFilter implements WordFilterInterface {

@Override
public String name() {
return "Lowercase";
}

@Override
public String definition() {
return "Turns the word to lowercase";
}

@Override
public String process(String word) {
return word.toLowerCase();
}

@Override
public String toString() {
return name();
}

}

Interested in a NetBeans Platform training too? Go here for all the details.

 

Build and launch faster with Okta’s user management API. Register today for the free forever developer edition!

Topics:

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}