• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Setting Glassapane on JInternalFrame

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 1535
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic