Place JComponent On The Top Of JXLayer

Posted by Yan Cheng CHEOK on Stack Overflow See other posts from Stack Overflow or by Yan Cheng CHEOK
Published on 2010-04-17T16:01:28Z Indexed on 2010/04/17 16:03 UTC
Read the original article Hit count: 280

Filed under:
|

Hello, currently, I had successful applying JXLayer on my charting component, to draw a yellow information box on the top of it.

alt text

final org.jdesktop.jxlayer.JXLayer<ChartPanel> layer = new org.jdesktop.jxlayer.JXLayer<ChartPanel>(this.chartPanel);
this.chartLayerUI = new ChartLayerUI<ChartPanel>(this);
layer.setUI(this.chartLayerUI);

At the same time, I wish to add the following JComponent (DefaultDrawingView) on the top of JXLayer. This JComponent has the ability

1) To receive mouse event to draw figures on itself.

alt text

Within ChartLayerUI, I add the following code

@Override
@SuppressWarnings("unchecked")
public void installUI(JComponent c) {
    super.installUI(c);
    JXLayer<JComponent> l = (JXLayer<JComponent>) c;
    l.getGlassPane().setLayout(new java.awt.BorderLayout());
    // this.view is DefaultDrawingView drawing object.
    l.getGlassPane().add(this.view, java.awt.BorderLayout.CENTER);
}

However, after having the above code, I get the following outcome alt text

1) My charting component ChartPanel are being blocked by DefaultDrawingView

2) My charting component no longer able to receive mouse event.

What I wish is that

A) ChartPanel and DefaultDrawingView able to show up

B) ChartPanel and DefaultDrawingView able to receive mouse event

Is there other steps I had missed out, or did wrong?

Thanks.

© Stack Overflow or respective owner

Related posts about swing

Related posts about java