GUI in 2Dimensions

Flexing with Swing

Archive for the ‘Swing’ Category

JTable row resizing using ..JxLayer

Posted by Pavan Kumar on September 16, 2010

A common usecase for a JTable is to  manually resize rows .  One  solution  googled was   Make JTable Resizable

It works fine with a couple of drawbacks..

  • If the CellEditor gets activated on mouseMove(as in my application) the mouse events will be consumed by the editor component , and the table mouseListeners(for  Dragging) will Not be notfied.
  • Working around the problem of rowSelection,when resizing ..needed the underlying table to be modified.

This seemed a perfect usecase for JxLayer

  • Get all MouseEvents from any component parented by the underlying Table.
  • Lock the UI on MouseMove & prevent the RowSelection in the table from changing(on mousePressed).

The class RowResizerUI extends LockableUI(from JxLayer) &  provides  row resizing for the underlying table.

Link to Src


Posted in GUI, Java, Swing | 2 Comments »

Java Swing Application ‘Always on Top’

Posted by Pavan Kumar on October 14, 2009

Since the last few weeks  , our  Java Swing Client  sporadically..seems to set itself  on top of every other windows application.  As things always happen, the problem was occasionally reproducible by our testing team, but  not  by our development team..but it was a big problem for our clients to have their numerous window apps  open behind our Swing app.

So finally I decided to investigate further ….a cursory search in the Sun Bug Database took me to

which explains the issue wonderfully….and the best  part was that  it was always Reproducible !

The bug states that  ‘Modal dialog causes the underlying parent JFrame to be set to Always on top’. Here are the steps to reproduce the bug

1) Open a JFrame (note the "alwaysOnTop" is not set to true).
2) Spawn a Modal Dialog with 'Always on Top' , From the Frame
3) While the dialog is open ,click on the underlying Frame (nothing happens as modal dialog is blocking it).
4) Now close the dialog and suddenly the parent JFrame is now set to be always on top. It won't happen if  the parent Frame ,was NOT clicked on while the dialog was open.

The worst part of the bug is the fact that ‘Always On Top’ property of the Frame is false although the Frame itself is visually always on top.

One workaround as mentioned is to ..

setAlwaysonTop(true)..followed by….setAlwaysonTop(false) , on the Main Window whenever a modal dialog closed .

This bug seems to have crept in only after JRE 6 Update 11  , and was submitted in early April… Hopefully it would get fixed in the upcoming releases …..

Posted in GUI, Java, Swing | Leave a Comment »

Showing Progress without blocking the Entire application

Posted by Pavan Kumar on March 12, 2008

A very common usecase  in Gui applications is to show an indeterminate progress bar whenever there is a long running task. Tasks can range from short ones such as data fetch to long ones such as a data migration or complex computations. In case of long running tasks it makes sense to show progress, but at the same time allow the user to perform other actions or work on other screens parallely ,within the application.

Swing allows us to achieve this functionality rather easily.

The demo below shows this functionality.

The overlay progress is shown whenever the tree is expanded and the nodes are loaded using swingworker, while u can continue to work on the table on the right .


The OverlayProgressContainer component enables us to do just this.

1: It makes use of the lesser known but very helpful Overlaylayout to stack components .
2: It has 2 children
a) User defined panel added as the bottom most child
b) GlassPanel added as the top most child .This panel shows progress using the JxBusyLabel and blocks keyboard(using KeyEventDispatcher),mouse events on the user defined panel .

3: The glasspanel is registered as listener to a swing worker and shows the progress based on the states(‘started’, ‘done’) of the swing worker

To make use of this component
1: Set the user defined panel using setDecoratedComponent(JComponent component)..
2: Set the swingWorker so that glasspanel can registered itself using setSwingWorker(SwingWorker worker)
Note: SwingWorker can be used only once and hence has to be created again once it has finished executing.

Link to Sources

Posted in Swing | 3 Comments »