• 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 ...
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
  • Mikalai Zaikin

Swing - detect mouse click outside modal JDialog boundary

Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a JFrame with objects located on it at specific positions.

I'd like to pop up a modal JDialog on top of that JFrame and let the user click on the object pixels on the underlying JFrame and detect those mouse clicks from within the JDialog so that I can show some meta information from within the JDialog.

I know that the user cannot click on the actual JFrame objects once the JDialog is showing, but if they move the JDialog to the side, they can physically click the mouse on the pixel locations of the JFrame objects, and it's those clicks I'd like to detect from within the JDialog.

When I look at the standard MouseEvent's they all seem to be constrained to the JDialog boundaries (which is fair enough for normal use), and I know that what I'd like to do here is non-standard, just wondering if anyone has any ideas on how I might approach it.

Posts: 43081
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

As a user I would not expect that clicking on the main window brings up help about the dialog in front of it. Why not make the help functionality obvious by adding a small icon or label labelled "Help" to the dialog?
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I guess i know what you want to do.
But the dialog is modal so you wont be able to capture the clicks.
I was wondering if you can do it by making another frame instead of the dialog
& turning it always-on-top(only in Tiger).

A very raw example :

import javax.swing.*;
import javax.swing.DefaultComboBoxModel;
import java.awt.event.*;

class H
public static void main(String[] args)
JFrame frame = new JFrame();
JFrame iframe = new JFrame();
final JLabel lbl = new JLabel("Hello");
String[] petStrings = { "Bird", "Cat", "Dog", "Rab@bit", "Pig" };
iframe.setAlwaysOnTop(true); // only in 1.5
}catch(Exception e){e.printStackTrace();}

//Create the combo box, select item at index 4.
//Indices start at 0, so 4 specifies the pig.
JComboBox petList = new JComboBox(new DefaultComboBoxModel(petStrings));
petList.addItemListener(new ItemListener(){
public void itemStateChanged(ItemEvent e){
[ January 08, 2007: Message edited by: Vishal Mungi ]
    Bookmark Topic Watch Topic
  • New Topic