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

Discussion in 'Java' started by Wolfgang, Apr 26, 2004.

  1. Wolfgang

    Wolfgang Guest

    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
    Wolfgang, Apr 26, 2004
    #1
    1. Advertising

  2. Wolfgang

    Guest

    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...ml#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.
    , May 1, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Bryan R. Meyer

    Glasspane and Saving Graphics

    Bryan R. Meyer, Sep 13, 2003, in forum: Java
    Replies:
    8
    Views:
    3,084
    Bryan R. Meyer
    Sep 16, 2003
  2. Dave Smithz
    Replies:
    11
    Views:
    1,344
  3. Dave Smithz
    Replies:
    3
    Views:
    7,662
  4. Dhananjay
    Replies:
    1
    Views:
    1,090
    sloan
    Dec 18, 2006
  5. Icarus
    Replies:
    5
    Views:
    551
    Icarus
    Aug 3, 2008
Loading...

Share This Page