David Qiao's Blog

Java and Swing

Introducing MarqueePane component to the open source JIDE Common Layer

by David Qiao on Jun.18, 2009, under JIDE, Java and Swing

In the 2.6.6 release, we introduced a small cool component called MarqueePane to JIDE Common Layer. It is open source so please fee free to give it a try. You can use it to auto-scroll any component. It is perfect for use cases such as an auto-scrolling stock tick display or an auto-fliping status, You can run webstart demo to see MarqueePane in action.

MarqueePane

Leave a Comment more...

What’s wrong with Apple

by David Qiao on Jun.16, 2009, under JIDE, Java and Swing, Mac

Apple just released a new JDK6 on Mac. It is suppose to be a good news but it turned out to be a nightmare. They changed the package structure of Aqua L&F. Many classes that were under apple.laf package are now under com.apple.laf. This breaks pretty much everything we tried to make JIDE looking decent enough on Mac. Even more, I could change our code to use the new classes but how to make it compatible with both old and new JDK? Two sets of JIDE clasess or even two release packages? It is really werid to see Apple did such a strange thing in a minor JDK update (maybe make sense for JDK 7). Hope someone from Apple Java team can give me an explantion.

6 Comments more...

Want to share your table screenshots?

by David Qiao on Mar.03, 2009, under Conferences, JIDE, Java and Swing, Technology

I got a technical session for JavaOne 2009 to talk about JTables. I knew JTables and JIDE Grids are used very widely among JIDE customers. So I am very eager to collect some screenshots from real applications to show what tables look like in the real world. It doesn’t have to be JIDE Grids. It could be a JTable with customization or JXTable or your own table component. I will dedicate a few minutes from the session to show those screenshots to the audience. I will of course give the credit to you. If you are interested, please email me david at jidesoft.com. I am looking forward to hearing from you!

Leave a Comment more...

Arrow key support in ButtonPanel

by David Qiao on Jun.22, 2008, under JIDE, Java and Swing

There is one missing feature in ButtonPanel. That’s the arrow key support. On Windows (probably on Mac as well), people get used to use left or right keys to navigate among buttons on a horizontal button panel or up/down keys for vertical button panel. However Swing doesn’t have that. For example, in the JOptionPane, arrow keys don’t change button focus. So I decide to add this feature. it has about 200 lines simple code. I included it below. The javadoc tells you how to use it. It is already checked in to JIDE Common Layer so feel free to check it out and use it. JIDE’s ButtonPanel called it already. JideOptionPane, since it uses ButtonPanel, also works beautifully.

Leave a Comment :, more...

Slides and demo source code for my JavaOne 2008 BOF session

by David Qiao on Jun.06, 2008, under Conferences, Java and Swing, Technology

As I mentioned before, I had an interesting BOF session for the this year JavaOne. The title is “Workaround Swing Bugs”. Even though it was conflicted with the afterdark party, there was still a decent number of people showed up. Since several people asked for it, I post the slides and the demo source code below.

Slides for BOF-5133
Demo Souce Code for BOF-5133

Leave a Comment more...

Discussions on Swing, RIA and JavaFX

by David Qiao on May.24, 2008, under JIDE, Java and Swing, Technology

Kirill just posted an interview with me on his blog on Swing, RIA and JavaFX. It is a series of interviews with Amy Fowler, Mikael Grev and myself. I guess Kirill probably will have more interviews after the first three. Interesting discussions.

Leave a Comment more...

JWebPane

by David Qiao on May.08, 2008, under Conferences, Java and Swing, Technology

This is something Java/Swing community has been crying for years. We even received numerous requests to make such a component (and we declined all requests). That’s a lightweighted Swing component for html viewing (or editing). JDIC gave us some hope several years ago even though it is JNI based but that’s project went nowhere. There was no indication that Sun is working on it, until the first day of JavaOne when a JWebPane component was announced. Surprise! The demo looked pretty good. It is just there is no demo for public to play with at the moment. I am certainly eager to give it a try when it is avaialble in June or July.

For those whose are interested in it, the author just posted a blog on it.
http://weblogs.java.net/blog/ixmal/archive/2008/05/introducing_jwe.html

Leave a Comment more...

JDAF 2.0 official release

by David Qiao on Apr.15, 2008, under JIDE, Java and Swing, Technology

After nine month beta period, we finally release JIDE Desktop Application Framework officially. Comparing to other JIDE component products, JDAF is a whole different story. It is a ground-breaking platform for developing truly cross-platform desktop applications in Java and Swing. There are many concepts in JDAF that are the first of its kind, such as Managed UI, OS-guideline driven Application UI, built-in MVC and FileFormat etc. It also provides easy integration with JIDE Docking/Action Framework and DocumentPane. I encourage to check out the JDAF product page or the self-guided JDAF tutorial to learn more about JDAF and find out how it can make your application development easier.

Leave a Comment more...

Auto-fit visible rows only

by David Qiao on Mar.08, 2008, under JIDE, Java and Swing

I don’t like Vista as it is apparently slower than XP. However I discovered something nice about it. Today, I was doing a build on Vista and I double clicked on Explorer table header to auto-fit a column, I noticed it didn’t fully expanded as I knew there is a long file name in this folder. Bug? I soon realized it only auto-fits the cells that are currently visible. I have to say this is a great idea as user only cares about what they can see when they auto-fit. I verified on Windows XP, it doesn’t work like that so it is obviously a new feature Vista introduced.

TableUtils class in JIDE Grids has autoResizeAllColumns and autoResizeColumn method which will auto-fit the columns in a JTable. If JideTable#setColumnAutoResizable(true), user can double click on the table column header between two columns to auto-fit the column, just like what Excel and Explorer (pre-Vista) does. It worked greatly. However when there are a huge number of rows in that table, or the getValueAt method of the table model is very slow, the cell renderer is slow to create, it could take a long time. User reported this issue on PivotTablePane as the autoResizeAllColumns method is slow on huge pivot table. I’ve been spent time to tune it but still not satisfied with it. But this new discovery on Vista gives me the hope. I quickly changed the code and added an extra parameter “visibleRowsOnly” to TableUtils#autoResizeColumn(…). The performance is excellent (of course, as there are only 20 visible rows when I tested on a table with 10000 rows) as it took less than 1 ms comparing to ~200 ms before. So if you are using this feature in JIDE Grids, you can consider using this new feature if it makes more sense to auto-fit the visible rows only in your application.

Leave a Comment more...

Rotate an Icon in Java

by David Qiao on Feb.29, 2008, under JIDE, Java and Swing

One user asked us to add a method to IconsFactory to rotate an icon for any angle. Sounds like a simple thing to do but it took me a while to get it right. It is checked in to JIDE Common Layer as part of 2.2.2 release. See below for the complete source. Feel free to use it.

final static double DEGREE_90 = 90.0 * Math.PI / 180.0;

    /**
     * Creates a rotated version of the input image.
     *
     * @param c            The component to get properties useful for painting, e.g. the foreground
     *                     or background color.
     * @param icon         the image to be rotated.
     * @param rotatedAngle the rotated angle, in degree, clockwise. It could be any double but we
     *                     will mod it with 360 before using it.
     *
     * @return the image after rotating.
     */

    public static ImageIcon createRotatedImage(Component c, Icon icon, double rotatedAngle) {
        // convert rotatedAngle to a value from 0 to 360
        double originalAngle = rotatedAngle % 360;
        if (rotatedAngle != 0 && originalAngle == 0) {
            originalAngle = 360.0;
        }

        // convert originalAngle to a value from 0 to 90
        double angle = originalAngle % 90;
        if (originalAngle != 0.0 && angle == 0.0) {
            angle = 90.0;
        }

        double radian = Math.toRadians(angle);

        int iw = icon.getIconWidth();
        int ih = icon.getIconHeight();
        int w;
        int h;

        if ((originalAngle >= 0 && originalAngle <= 90) || (originalAngle > 180 && originalAngle <= 270)) {
            w = (int) (iw * Math.sin(DEGREE_90 - radian) + ih * Math.sin(radian));
            h = (int) (iw * Math.sin(radian) + ih * Math.sin(DEGREE_90 - radian));
        }
        else {
            w = (int) (ih * Math.sin(DEGREE_90 - radian) + iw * Math.sin(radian));
            h = (int) (ih * Math.sin(radian) + iw * Math.sin(DEGREE_90 - radian));
        }
        BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
        Graphics g = image.getGraphics();
        Graphics2D g2d = (Graphics2D) g.create();

        // calculate the center of the icon.
        int cx = iw / 2;
        int cy = ih / 2;

        // move the graphics center point to the center of the icon.
        g2d.translate(w/2, h/2);

        // rotate the graphcis about the center point of the icon
        g2d.rotate(Math.toRadians(originalAngle));

        g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
        icon.paintIcon(c, g2d, -cx, -cy);

        g2d.dispose();
        return new ImageIcon(image);
    }

Notes: updated after taking Ken’s suggestion. Thanks Ken.

Leave a Comment more...

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!