Archive for the 'Java' Category

Nimbus: Large, Small, Mini Components

Friday, December 7th, 2007

In the original design for Nimbus there were large,small and mini versions of components. Small and mini components are very useful when you are creating tool pallets or other UI where space is very tight. Apple recently added this to their new look and feel in the latest java versions see Technical Note TN2196. We are using the same client property key and values as Apple to be compatible but I have also added “large” as a option. Not sure “large” is as useful as “small” or “mini” but might look good in wizards or dialogs. Check out the screenshot to see how they look. Nimbus Small Mini 600

Faster Swing Lists and Tables up to 88,000x

Tuesday, November 6th, 2007

Swing lists and tables use an implementation of ListSelectionModel to handle keeping track of the selection. Every time you change the selection or rows then the component sends those changes to the selection model to keep it in sync. The default implementation that you get is DefaultListSelectionModel. Its implmentation is highly optimized for certain kinds of operations but has had to make comprimizes for a some other operations.

Back when I was doing Imagery I created an alternative implementation of ListSelectionModel because I needed an easy way to convert the selection into a SQL where clause. After much thought I came up with the idea of representing the selection as a list of ranges of selected ids. This means that you can then convert the selection into a list of "id >= rangeMin AND id <= rangeMax" SQL expressions. This solution is well suited to the case where the selection is created by the user. The only way for a user to create more than one range is to “Control” click the rows. It is unlikely that the user will ever select more than a couple dozen ranges. This results in a model that is always simple however many rows there are in the List/Table. As a by product of this alternative selection model can be up to 88,000x faster than the default with large amounts of rows. I have put together a couple of JUnit tests, one does a huge amount of random operations on both a DefaultListSelectionModel and a RangeListSelectionModel and compares the results at each stage. This means that I can be very sure that my implementation is fully compatible with the default one. The second unit test does some performance tests to compare the two models. The data set is 1,000,000 rows and 20,000 operations for each test

Performance Results

Test Default Model Ranges Model Perfomance Gain
Add selection interval 0.017 s 2.533 s -149x
Is selected index 0.009 s 0.011 s -1.2x
Remove index interval 16:09 min 0.011 s 88,053x
Set selected item 1:30 min 0.067 s 1405x
20k Random Operations 4:25 min 0.055 s 4810x
Average 18,823x

As you can see from the results that it is a large win on average. The test that it is slow at is AddSelectionInterval this is because it ends up with 17482 ranges. This should never happen in most real world applications, the only way I can see it happen is if you select all table rows that meet some search criteria which results in 1000s of random rows being selected. In all cases where the selection is user controlled then this will never happen.

Conclusion

I have seen bug reports coming in of hugely bad JTable performance when adding/removing rows from a huge table. After profiling I found that it was the SelectionModel causing the problems. You can see from the performance results that it can take minutes to do a large chunk of selection changes on a big table. So please try out my Ranges implementation in your application and tell me how it performs. If the responses are good I could change it to the default ListSelectionModel implementation in Java 7. To use it you just need to add the line “myTable.setSelectionModel(new RangeListSelectionModel());“.

Code Downloads

Here are the sources so you can try it out for yourself:

Java Icon
RangeListSelectionModel.java
Java Icon
RangeSelectionModelPerformanceTest.java
Java Icon
RangeSelectionModelTest.java

JavaOne 2008 Papers

Tuesday, October 30th, 2007

Its already that time of year again to start writing up all your great ideas for Java One Desktop talks for next year. Its only two and a half weeks till they close for submissions so hurry up. Click here for details for paper submission.

I am planning on submitting a talk on Nimbus and the new Nimbus Designer tool. Covering:

  • Using Nimbus L&F in your applications
  • Designing for cross-platform, how to design your application to look good on all platforms
  • Customizing Nimbus
  • Creating new look and feels using the designer tool based on Nimbus
  • Creating your own components with Nimbus L&F themeing support
  • Designing the look for your own components using the deisgner tool

Might have too much to cover in a hour, don’t want to scare you all off. Any thoughts on what topics you think are the most important/intresting in case I need to cut bits out or anything I didn’t mention here?

JavaOne 2008

Come join the Swing Team

Tuesday, October 30th, 2007

Swing Duke

We are looking for someone to come join us and help develop the next generation of Java Desktop. Lots of cool fun projects looking for a passionate Swing guru.

  • Experience with developing Swing applications required.
  • Passion for Desktop and Rich Client Applications
  • Interest in designing new API for future versions of Java
  • Interested in helping write cool demos for Java One and just generally showing off our technology
  • Need to be in the San Francisco Bay Area or willing to move there. Also you need to be a US citizen or be able to get a visa to work in the US.

This is an amazing opportunity to work with the team who have created and shaped Desktop Java with the chance to influence the future of Java yourself. If you are interested then you can email me via the link below. Please send screenshots or links to any Swing applications you have worked on.

Email Me

Nimbus Early Access

Monday, October 1st, 2007

Finally a version you can all go and play with. Nimbus is coming out as part of “Java SE 6 update N” formerly known as the “Consumer Release” and “Project Hamburg”. Well whatever it is called it contains a decent version of the new Nimbus look and feel. You can go and download it from Java SE 6 Update N Early Access Program. Its is definately not 100% finished yet, there are a few areas that we are still working on:

  • Tabs
  • Focus handling is missing from Spinner,Slider, Tree, Table and List
  • FileChooser has a lot of issues
  • Right to Left for international language support
  • 3rd party component theming
  • Color theming
  • Lots of minor things like table gridlines or setContentAreaFilled() support on buttons
  • Exceptions are thrown if the window or some components get too small

Most of these will be fixed in the next EA release or the first beta release. A few of them have been fixed in the last couple weeks, I have just been working on color theming. All colors in Nimbus are derived from a set of UIDefault colors with Hue, Saturation and Brightness offsets. This gives you reasonable control over changing the colors of the Nimbus Look and Feel.

Dark NimbusDarker Themed Nimbus

Using Nimbus

There are 3 easy ways to use the Nimbus look and feel:

  1. If you query UIManager for a list of available look and feels then Nimbus will show up in the list
  2. Add UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); to your application before creating any Swing components
  3. To specify the L&F from command line, use the following when running your Java application: -Dswing.defaultlaf=com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel

The reason Nimbus is in the sun.swing… package is it is not possible to add new API to the javax.swing… package in a update release. We hope that we can move Nimbus to javax.swing in Java 7 and if it turns out to be popular then we push to make it the default look and feel in 7. Before 6 update N is final we will work out some way for you to be able to use it now and when it is potentially moved without changing any code.

If you Find Bugs

You can search to see if there is an existing at Sun Bug Database or you can view a List of open Nimbus Bugs. You are welcome to post bugs here as comments and I will file them if they are not known bugs.

Other Cool Features of Update N

Improved performance

  • The Quick Starter feature will prefetch portions of the JRE into memory, substantially decreasing the average JRE cold start-up time (the time that it takes to launch a Java application for the first time after a fresh reboot of a PC).
  • Hardware acceleration support: Java SE 6 Update N introduces a fully hardware accelerated graphics pipeline based on the Microsoft Direct3D 9 API, translating into improved rendering of Swing applications which rely on translucency, gradients, arbitrary transformations, and other more advanced 2D operations.

Enhanced JRE installation experience 

  • The Deployment Toolkit takes the guess work out of determining what versions of the JRE end users have installed on their PC. It supplies Java based web applet/application deployers with a simple interface to accomplish Java detection and installation.
  • The Kernel installation mode lets first time Java users run applets and Web Start applications without waiting for the whole JRE download. While the default Kernel installation will work with existing Java applets, application developers have the ability to select libraries that should be installed with the kernel, before the rest of the JRE is installed on the end user’s system.
  • For current users of Java SE, the JRE update mechanism has also been improved, using a patch-in-place mechanism that translates in a faster and more reliable update process (the patch in place mechanism will take effect for end users who upgrade from this update release or later to a new update release). As an added benefit, follow-on update releases will no longer be listed as separate items in the Windows “Add or Remove Programs” dialog.
  • A new Java update download engine provides end users with the convenience of pausing and resuming the JRE download, and relies on a more reliable download mechanism.