aspose file tools*
The moose likes Swing / AWT / SWT and the fly likes Setting Glassapane on JInternalFrame Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Swing / AWT / SWT
Bookmark "Setting Glassapane on JInternalFrame" Watch "Setting Glassapane on JInternalFrame" New topic
Author

Setting Glassapane on JInternalFrame

Chandrashekhar Nathile
Greenhorn

Joined: Sep 22, 2006
Posts: 5
Hello Friends,

I am using JInternalFrame which contains JScrollPane (which contains JTextArea) now i want to set Glass Pane on that JInternalFrame but when user click on scrollpane's scrollbar event must be dispatched to that scrollbar so i write following code

myInternalFrame.getContentPane ().add (mTextAreaScrollPane);

// glasspanel is object of class that extends JComponent ie Myglasspanel

Myglasspanel glassPanel = new MyGlassPanel (myInternalFrame.getContentPane())

myInternalFrame.setGlassPane (glassPanel);



// Following is constructor of Myglasspanel

/**
public MyGlassPanel(Container myInternalFramecontentpane)
{

ScrollPaneListener listener = new SrollPaneListener(this,myInternalFramecontentpane);
addMouseListener (listener);
addMouseMotionListener(listener);
}
*/
In Mouseclick event i write following code

public void mouseClicked(MouseEvent event)
{
Point glassPanePoint = event.getPoint();
Point containerPoint = SwingUtilities.convertPoint(glasspanel, glassPanePoint, myInternalFramecontentpane);
if (containerPoint.y > 0)
{
//The mouse event is probably over the internal frame's content pane.
//Find out exactly which component it's over.
Component component = SwingUtilities.getDeepestComponentAt(myInternalFramecontentpane, containerPoint.x, containerPoint.y);

// Here I got �javax.swing.JScrollPane$ScrollBar� as component when I click on scrollbar
System.out.println("Comp is" + component.getClass().getName());

if ((component != null) && ((component instanceof JScrollBar) || (component instanceof MetalScrollButton)))
{
Point componentPoint = SwingUtilities.convertPoint(glasspanel, glassPanePoint, component);

//Forward events over the scrollbar.
component.dispatchEvent(new MouseEvent(component, event.getID(), event.getWhen(), event.getModifiers(), componentPoint.x, componentPoint.y, event.getClickCount(), event.isPopupTrigger()));

}
}
But still that event is not dispatched to scrollbar .
So please help me out ,

Thanks in advance
[ October 10, 2006: Message edited by: Chandrashekhar Nathile ]
Craig Wood
Ranch Hand

Joined: Jan 14, 2004
Posts: 1535
One problem with this is that we can get the event to the JScrollBars but the MouseEvent goes to the track and not the thumb. So we get a unit increment scroll but are unable to drag the thumb. If we follow the scrollBar ui down to BasicScrollBarUI there is a getThumbBounds method with protected access modifier. So this approach leads to writing some plaf code.
I wonder if there is an easier way to do this but don't know why you are using a glass pane (I'm stuck here). One thing I noticed is that the glass pane visibility is toggled to off when selecting (mouse clicks on) the JInternalFrame title bar. This seems self–defeating.
An alternative might be to add a non–opaque JComponent as an overlay above the JTextArea leaving the scrollPane controls free/accessible. This would cover the entire JTextArea, could take graphics and would not interfere with mouse events meant for the text area below. Of course I haven't tried this, just spinning some ideas.
Or, if graphics is what you're after you might be able to draw over the JTextArea.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Setting Glassapane on JInternalFrame
 
Similar Threads
JOptionPane Modal Internal Frame Focus Traversal
drag n drop of icon
JTabPane Problem
GlassPane not redirecting events to deeper components
how to implement non rectangular components e.g.Circle