Using transparent layer for data input (glassPane?) over another layer

W

Wolfgang

I have an application that allows use of the mouse to drag and move an
image, which is a map. Clicking and dragging the left mouse button
will do that -- it works fine. See the following screenshot (the
white dot at the lower left of the white writing is the place where
the mouse has grabbed the image):

http://alex2.alexandria.ucsb.edu/~rnott/tmp/layer1_nofieldsorbuttons_movablemap.jpg

Now I want to overlay some data input fields (text fields), menues and
buttons on top of the map, and they are supposed to stay in a fixed
position. So when I'm over the map, I want to be able to drag and
move the map (which presumably is in one layer), and when I'm over a
field, menu or button I want to be able to enter and accept data,
click the button, etc. This presumably would happen in another r
layer, and a mockup screenshot might look like this:

http://alex2.alexandria.ucsb.edu/~r...nlyfieldsandbuttons_seeingthroughtolayer1.jpg

How would you do that? Can you have two independently controllable
layers, whith the top one (the one with the text field) mostly
transparent, except of course in the area of the text field.

Thanks for any advice.

Wolfgang,
Santa Barbara, California
 
M

mromarkhan

Peace be unto you

Here is a thought...

Conclusion
if != 1.5
use JLayeredPane
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html
if == 1.5
use container.setComponentZOrder
http://java.sun.com/j2se/1.5.0/docs...l#setComponentZOrder(java.awt.Component, int)

Poor display of workmanship follows

1.4
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class JNNTP extends JFrame
{
public JNNTP()
{
JComponent newContentPane = new LayerHolder();
newContentPane.setOpaque(true);
this.setContentPane(newContentPane);
this.pack();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

}
public static void main(String [] args)
{
JNNTP nntp = new JNNTP();
}
public class LayerHolder extends JPanel
{
private JTextArea consoleText;
private JLayeredPane layeredPane;
private JCheckBox showHeaders;
private JScrollPane textScroll;
public LayerHolder()
{
layeredPane = new JLayeredPane();
layeredPane.setLayout(null);
layeredPane.setPreferredSize(new Dimension(512, 342));
showHeaders = new JCheckBox("Show Headers");
showHeaders.setOpaque(false);
showHeaders.setBounds(
0,0,200,40);
consoleText = new JTextArea("Version note: In 1.5,\n"
+"we expect that API will be added to allow\n"
+"direct manipulation of a Component's Z order within\n"
+"a container. When this is available, you won't need\n"
+"to use a JLayeredPane to assign a Z order to a\n"
+"lightweight component.");
textScroll = new JScrollPane(consoleText);
textScroll.setBounds(0,0,512,342);
layeredPane.add(textScroll,JLayeredPane.MODAL_LAYER);
layeredPane.add(showHeaders,JLayeredPane.POPUP_LAYER );
setLayout(new BorderLayout());
add(layeredPane, BorderLayout.CENTER);
}
}
}

1.5
"C:\Program Files\Java\j2sdk1.5.0\bin\javac.exe" JCup.java
"C:\Program Files\Java\j2sdk1.5.0\bin\java.exe" JCup
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class JCup extends JFrame
{
private JTextArea consoleText;
private JLayeredPane layeredPane;
private JCheckBox showHeaders;
private JScrollPane textScroll;
public JCup()
{
this.setLayout(null);
showHeaders = new JCheckBox("Show Headers");
showHeaders.setOpaque(false);
showHeaders.setBounds(0,0,200,40);
consoleText = new JTextArea("Version note: In 1.5,\n"
+"we expect that API will be added to allow\n"
+"direct manipulation of a Component's Z order within\n"
+"a container. When this is available, you won't need\n"
+"to use a JLayeredPane to assign a Z order to a\n"
+"lightweight component.");
textScroll = new JScrollPane(consoleText);
textScroll.setBounds(0,0,512,342);
this.addComponentListener(new LayIt());
this.getContentPane().add(textScroll);
this.getContentPane().add(showHeaders);

//Where components overlap,
//the component with the
//lower z-order paints over the component with the higher z-order.
this.getContentPane().setComponentZOrder((Component)textScroll,1);
this.getContentPane().setComponentZOrder((Component)showHeaders,0);
this.setSize(512,342);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.setVisible(true);

}
public static void main(String [] args)
{
new JCup();
}

public class LayIt extends ComponentAdapter
{
public void componentResized(ComponentEvent e)
{
textScroll.setBounds(0,0,e.getComponent().getWidth() - 90,
e.getComponent().getHeight() - 90);
}
}
}

Have a good day.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top