This week's book giveaway is in the Programmer Certification forum.
We're giving away four copies of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 and have Jeanne Boyarsky & Scott Selikoff on-line!
See this thread for details.
Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Swing - detect mouse click outside modal JDialog boundary

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • 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.

Cheers
James
 
Rancher
Posts: 43011
76
  • Mark post as helpful
  • send pies
  • 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?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • 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");
iframe.getContentPane().add(lbl);
String[] petStrings = { "Bird", "Cat", "Dog", "Rab@bit", "Pig" };
try{
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){
lbl.setText(e.paramString());
}
});
petList.setSelectedIndex(3);
frame.getContentPane().add(petList);
frame.pack();
frame.setVisible(true);
iframe.pack();
iframe.setVisible(true);
}
}
[ January 08, 2007: Message edited by: Vishal Mungi ]
 
Beware the other head of science - it bites! Nibble on this message:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!