X

Geertjan's Blog

  • April 13, 2007

Library List in the IDE's Toolbar

Geertjan Wielenga
Product Manager
On the face of it, this isn't the most useful functionality. A JComboBox, with a filter, in the IDE's toolbar, for displaying all the libraries in the IDE's Library Manager:

However, knowing how to get the libraries from the Library Manager is pretty useful in some cases. For example, in the Frameworks panel in the New Project wizard for web applications, you might want to show all the libraries (or a filtered list, meeting certain criteria), so that the user can choose one of them to be put on the classpath.

So, in the above scenario, you need to declare a dependency on "External Libraries". This is the code, called from the JPanel's constructor, as well as in the (optional) filter's keyPressed event:

private void initLibraries(){
Library libraries[] = LibraryManager.getDefault().getLibraries();
Vector items = new Vector();
ArrayList allLibraries = new ArrayList();
String filter = jTextField1.getText();
for (int i = 0; i < libraries.length; i++) {
if (libraries[i].getName().startsWith(filter)){ //NOI18N
String displayName = libraries[i].getDisplayName();
items.add(displayName);
allLibraries.add(libraries[i]);
}
}
jComboBox1.setModel(new DefaultComboBoxModel(items));
if (items.size() == 0){
jComboBox1.setEnabled(false);
} else {
jComboBox1.setEnabled(true);
}
repaint();
}

And how do you create the toolbar in the first place? See the Google Toolbar Module Tutorial for details.

Join the discussion

Comments ( 1 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.