Overlapping components

I'm trying to write a card game, and I want to layout some cards with some overlap in a container. I'd like to do this with a standard Layout Manager if possible, rather than hardcoding it, but I can't find one which will do this - can anyone suggest on and how I can use it?
Thanks in advance,
Stefan

I'm trying to write a card game, and I want to layout
some cards with some overlap in a container. I'd like
to do this with a standard Layout Manager if possible,
rather than hardcoding it, but I can't find one which
will do this - can anyone suggest on and how I can use
it?
Thanks in advance,
StefanThere are many things that you can do. One is to override the draw function to draw everything. This is the coolest option, because you can nice things like rotate the cards when dealing and stuff like that.
Or an easier option is to use JLayeredPane, look at the tutorial, it has something very close to what you want!
http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

Similar Messages

  • Dispatching Events on overlapping Components

    Hello,
    i use a layered pane that contains some custom components. How can I make that two overlapping components that reside in the same layer both receive a mouseEvent?
    At the moment, only the Componet above receives the event - I know I can pass an Event with dispatchEvent - but i don't know the instance of the component to which to pass it of course... Is there any method to dispatch the event without having to know to which component to pass it?
    Any help appreciated.
    Best regards & Thanks.
    alex

    You can use use EventQueue.postEvent to post the event, but it requires source and if it is mouse event it will be later retargeted to correct components according to coordinates. So the only way for you to do this is to find the components by yourself and call processMouseEvent on it.

  • Overlapping components problem

    Hello,
    I have been developing an applet for Quickplaces. Basically it shows what is happening in the Quickplace from different kind of views. A view from a document where people can see who has been viewing it for example. Or a view from a member where one can see what documents the member wrote.
    Now I have chosen to implement a sort of circle visualisation for this. In the center is the object the view is about, a document, a member, etc. Outwards are other objects. In the case of a document view, the members that responded to it, in a circle more outward: members that viewed it. Etc. It's sort of a dartboard.
    I have written a custom layoutmanager for each view for this. A problem I have encountered is that once I tell a member or document component to let itself be placed by the layout managerr I get a fixed size component. It looks ok until you for example hover over it, wich I have keyed to a zooming in on details method. When you do that your usually overlapping other components. Why, components can be overlapped without zooming in some views. The problem is the mouselistener I have attached fires when I hover over de component size. Not the size of the actual graphical representation. My members for example are represented by a sphere. They are bounded by a rectangle component though. So if I enter my mouse anywhere near the sphere... it already zooms in, resulting in the user zooming in on a member, but actually he wanted to zoom in on a member that was close to this one, but for the code was "underneath" the component of the other member.
    It's a bit hard to explain without posting a screenshot.
    How do I fix this?

    Hi,
    I need a clarification, taking the example you
    provided:
    you have a rectangle components, that display spheres.I have a viewer class for document's member's and room's. RoomViewer, MemberViewer, etc. These paint the actual graphic. They are given a size by the custom layoutmanager i wrote like this:
            //Layout members
            int mems = members.size();
            if(mems != 0){
                double angle = 360 / mems;
                double baseAngle = 0;
                synchronized(members){
                     Iterator iter = members.iterator();
                     while(iter.hasNext()){
                         MemberViewer tempMember = (MemberViewer)iter.next();
                         Dimension d = tempMember.getSize();
                         double lastLog = tempMember.getMember().getLastLog() * 160 + Math.sqrt((Math.pow(50, (double)2) + Math.pow(50, (double)2)));
                         int xCoord = (int)((xCenter + (Math.cos(Math.toRadians(baseAngle)) * lastLog)) - (0.5 * d.getWidth()));
                         int yCoord = (int)((yCenter + (Math.sin(Math.toRadians(baseAngle)) * lastLog)) - (0.5 * d.getHeight()));
                         tempMember.setBounds(xCoord, yCoord, container_size, container_size);
                         baseAngle += angle;
            }A viewer get's it's data from the model class. MemberViewer from Member, etc.
    First you want to zoom only when the mouse is hovered
    on the sphere. Is that right ?Yes I have implemented the enters part of the mouselistener. As soon as the mouse enters the component in wich the graphical representation is drawn it zooms. with zoom I multiply the size by some and add some different graphs inside the circle, but that is not important. What is interesting is probably that the size of the component when it is not zoomed is the size for when it is zoomed in, or the zoom in would be cut off by the component boundaries.
    What about the overlapping ? could you clarify a bit
    please.
    Basically it overlaps nicely on the view. Once you interact though I get stuck. Clicking, entering and exiting is supposed to do things. But all these 3 fire when your mouse does that thing inside the component, not inside the graphical representation. So you start zooming quite a bit away from the circle of a member btw, because that distance is already part of the component, but not of the drawing.
    Who is reponsible for drawing the shapes ?The Viewers paint themselves. The Layoutmanager gives them a basic place to start their own painting and a View class controls the layoutmanager.
    And who listens to mouse motion ?The viewers themselves do. They implement mouseListener.
    in mouseMoved(MouseEvent e)
    you can get the point with e.getPoint(); where the
    mouse points to.
    This will help you to handle the event only when
    hovered on the shape,
    but it will maybe not solve the hovering over
    overlapped components.I don't quite follow that. A Shape can still not implement MouseListener.

  • Help! Image OverLapping components. Get Your dukes right here.

    I am creating an applet and I want to use an image as a background to a jPanel. There is a jTextField on the panel that is hidden because the BG image overlaps it. I would like the image to be used as a background and only as a background. Any Suggestions? Duke Dollars will be awarded.
    public class Tester extends JApplet
      Image imageTest;
      Graphics dbg;
      Image dbImage;
      JScrollPane jScrollPane1 = new JScrollPane();
      public Tester()
      public void init()
        try
          jbInit();
          imageTest = getImage( getDocumentBase(), "bg.gif");
        catch(Exception e)
          e.printStackTrace();
      private void jbInit() throws Exception
        this.getContentPane().setLayout(null);
        jScrollPane1.setBounds(new Rectangle(70, 30, 235, 215));
        jScrollPane1.setBackground(Color.black);
        jScrollPane1.setForeground(Color.white);
        this.getContentPane().add(jScrollPane1, null);
      static 
        try
          // UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
          // UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        catch(Exception e)
    public void paint(Graphics g)
        g.drawImage(imageTest, 0,0, this);
    }

    Check out this thread:
    http://forum.java.sun.com/thread.jsp?forum=57&thread=316074

  • Using a layout to allow overlapping components

    I want to implement some kind of swing component, as of right now I'm using a JLabel and painting an image on it, to create tiles of a game board.
    The problem is the tiles aren't square and I don't know how to allow the JLabels or JButtons or whatever component is easiest, to overlap in the places i need them to.
    Here is an image of the type of tiles I want to use.
    http://home.insightbb.com/~twilightimp/current_map.jpg
    Does anyone have any ideas?
    thanks

    Swing questions should be posted in the Swing forum. Here's an article that shows you how to create round buttons in Swing, maybe it will help.
    http://java.sun.com/developer/TechTips/txtarchive/1999/Aug99_PatrickC.txt

  • Multiple overlapping components hneed moved to be updated

    I have a dashboard that I designed that has main components then you can hide those and then show submenus that open up other items  to show where the main components used to be.  I have them hidden using dynamic visibility.  I have this for multiple submenus.  It works ok when playing the dashboard but updating or changing the dashboard is difficult because I have to keep moving components out of the way so I can get to other components that are below them in design mode but hidden and shown using dynamic visibility in play mode.  I am sure there are better ways to design this so I don't have to move components to change other components that are below them but don't know what or how to do anything different.  Please help.
    Thanks.

    Hey Brian,
    One of the things you can use is the object browser under the view menu. With this tool you can hide and unhide objects so it makes it easier to handle objects that are on top of each other.
    Hope this helps,
    Ben

  • Redraw problem when overlapping components

    As part of a project to automatically generate a GUI for a legacy application I found a problem that occures when I have to overlap JComponents (have to - because the basic layout is given by the legacy application). The following code demonstrates the problem:
    import java.awt.*;
    import javax.swing.*;
    public class Overlap
        public static void main(String args[]) {
            JFrame frame=new JFrame("test");
            JTextField text1=new JTextField("text1");
            JTextField text2=new JTextField("text2");
            JLabel label=new JLabel("LabelTest");
            label.setOpaque(true);
            Container content=frame.getContentPane();
            content.setLayout(new GridBagLayout());
            GridBagConstraints c=new GridBagConstraints();
            c.gridx=c.gridy=1;
            c.gridwidth=2;
            c.fill=GridBagConstraints.BOTH;
            content.add(label, c);
            c=new GridBagConstraints();
            c.gridx=c.gridy=c.gridwidth=1;
            c.fill=GridBagConstraints.BOTH;
            content.add(text1, c);
            c=new GridBagConstraints();
            c.gridx=2;
            c.gridy=c.gridwidth=1;
            c.fill=GridBagConstraints.BOTH;
            content.add(text2, c);
            frame.setVisible(true);
            frame.pack();
    }This gives a JFrame with a JLabel over two JTextField's - the JTextField's shoud be invisible. Actually you have a blinking cursor, the text of both JTextField's is selectable with the mouse, you are able to switch the focus between the JTextField's with the mouse ...
    Is there a way to force correct Z-order handling in this case?
    Tested with linux JDK 1.4, with 1.3 and 1.2 the initial drawing is done correctly but you are still able to select the JTextField's with the mouse.

    try to explain what you whant to doMh - as I said - it is a cooked down version of the problem. Imagine a 80x25 GridBagLayout (the base of this problem is a form based text mode application) with up to about 500 separate widgets in it. The problem now is that it is possible that some of these widgets overlap some others. So it is possible to place a label like widget over something that behaves like a textfield.
    Z order of a component is best made by using
    JLayeredPane objects can be added to the same layer
    but there will be problems if they overlapIn the case of JLayeredPane I think need to optimize the usage of them - when I take one for each widget then I'm sure I'm running out of the design specifications. But then I've to detect overlapping by myself.
    All this is a bit strange because there already is a Z-order defined when adding all this to one single JPanel - is the actual behaviour a swing bug or am I running out of the specified limits even there?

  • Layout that allows overlaping components

    I posted this in the general forum, I didn't know there was a swing forum:
    I want to implement some kind of swing component, as of right now I'm using a JPane; and painting an image on it, to create tiles of a game board.
    The problem is the tiles aren't square and I don't know how to allow the JPanels or JButtons or whatever component is easiest, to overlap in the places i need them to.
    Here is an image of the type of tiles I want to use.
    http://home.insightbb.com/~twilightimp/current_map.jpg
    Does anyone have any ideas?
    Do you think using a JLayeredPane to house all my tiles in would work, with the z-component increasing every row from the middle row?
    thanks
    Message was edited by:
    z0isch

    I got it working with JButtons and a JLayeredPane.
    =D

  • How do I bring components to front?

    Does anybody know, if I have overlapping components like JLabels, how can I choose which one to bring to the front?
    In other words, if I have two overlapping JLabels, how can I choose which one gets seen.

    I don't know if you can do this programmatically with one call (like the WinAPI setWindowPos and specify the z order and appropriate flag).
    Swing components are displayed in the order they are added to the container, with the first component being the top most.
    Regards,
    Nick G.

  • How do I see hidden components?

    If i have overlapping components (say JLabels or something) how can i shoose which one is to be seen?
    My problem is I have a large JLabel with the background image and several smaller JLabels with images i want to be seen. The large JLabel covers everything! How do I fix this?

    I dont want to hide anything... I just want to bring certain components to the front and others to the back. How do I do that?

  • How to tell if your component is being overlapped by another

    Hi,
    I've run into a problem implementing a menu bar into my program. Here's a little graphic. :)
              |  FILE     EDIT                                                              |
              |                                                                                            |
              |                                                                                            |
              |                                                                                            |
              |     Some custom component         CustomPanel     |
              |                                                                                            |
              |                                                                                            |
              |                                                                                            |
              ----------------------------------------------------------------------Except my component uses an active rendering loop, so it covers over the flip down menu. Is there anyway to tell when something is covering the CustomPanel? Or is there anyway to explicitly tell a component to paint all overlapping components on it?
    such as: CustomPanel.paintOverlappingComponents().
    or something like that?

    Menus in swing are light weight components i believe.
    if you want them to appear over the top of an actively rendered Component, you are going to need to either :-
    1) forcefully repaint the menus as part of the active rendering. (so, repainting them each loop)
    2) when performing the active rendering, add a clip region that excludes the area that the menus take up. (avoid overpainting them at all)
    In either case, you are going to have to query the menus each render loop, to determine if they are showing or not.
    I would go for solution 2, it should be quicker.

  • How to repaint a portion of a component?

    I am working with JLayeredPane and several overlapping components which I draw a selection rectangle around when the user clicks on a component to indicate that it is "selected". If the user selects another component I need to wipe out the selection rectangle on the previously selected component. I'm not sure what the best approach for this is.
    If the initially selected component was underneath (in a lower layer than) another component, I can't simply repaint it without repainting all of the components that are above it. This seems like it could be too much painting just to remove a selection box. Can someone recommend a good approach for this problem?
    Thanks,
    Jonathan

    Thanks for the response. The components should be on separate layers (added via JLayeredPane.add(JComponent) ) so if the painter takes the layers into account, then there must be something else wrong. Here's a quick demo program of what I'm doing:
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import javax.swing.*;
    import javax.swing.event.MouseInputAdapter;
    public class LayerDemo {
         private ControlMouseInputAdapter controlMouseInputAdapter = new ControlMouseInputAdapter();
    private static void createAndShowGUI() {
         LayerDemo layerDemo = new LayerDemo();
    JFrame mainFrame = new JFrame();
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception e) {;}
    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setSize(400, 400);
    JLayeredPane layeredPane = mainFrame.getLayeredPane();
    layeredPane.add(layerDemo.createColoredLabel("test1", Color.RED, new Point(20, 20)));
    layeredPane.add(layerDemo.createColoredLabel("test2", Color.BLUE, new Point(40, 40)));
    mainFrame.setVisible(true);
    private JLabel createColoredLabel(String text, Color color,
    Point origin) {
    JLabel label = new JLabel();
    label.addMouseListener(controlMouseInputAdapter);
    label.setText(text);
    label.setOpaque(true);
    label.setBackground(color);
    label.setBounds(origin.x, origin.y, 140, 140);
    return label;
    public static void main(String[] args) throws Exception {
    SwingUtilities.invokeLater(new Runnable() {
    public void run() {createAndShowGUI();}
    private class ControlMouseInputAdapter extends MouseInputAdapter {
    public void mouseEntered(MouseEvent e) {
    JComponent component = (JComponent) e.getSource();
    component.setBorder(BorderFactory.createLineBorder(Color.black));
    public void mouseExited(MouseEvent e) {
    JComponent component = (JComponent) e.getSource();
    component.setBorder(null);
    }

  • Two problems with displaying images in JPanel

    Hi,
    I need to display some small rectangular images inside a JPanel. These images also need to be componenents as they will have listeners associated with them. I have never had any experience with images, so I might totally be down the wrong path. I was thinking of just creating a class which extends JComponent, and using the graphics drawImage method. However, I don't want each image component to have to know exactly where to draw the image associated with itself. Rather, I want the JPanel which holds all of the images to know how to lay them out.
    Is there an easier way to use images?
    Which brings me to my second problem. I want these images to overlap each other, so that only a small portion of each is showing (this way I can fit more on the screen), then when the user clicks on one, I can show more of it.
    Unfortunately, I don't know of any layout managers which will allow me to overlap components. I could use the drawImage method mentioned above, but like I said, I would like to try to not have each image object try and figure out its location.
    any help is greatly appreciated. Thanks!

    Hi
    there is a better way ; it is called a JLabel ;-)
    JLabel myJLabel = new JLabel(new ImageIcon("img/myLogo.gif"));for your second problem, don't use any layout manager like in this code :
    myJPanel.setLayout(null);
    myJPanel.add(myJLabel);
    myJLabel.setBounds(new Rectangle(x, y, width, height);hope it helps
    Nico

  • Component to front

    If you have some overlapping components on a JPanel is there an Object you can call to bring the one you want showing to the front much like :
    frame.toFront();except with components on a JPanel.

    Just to add. I am trying to add a component A on top of component B, but with the way the compiler works when I add component A it is displayed behind component B. (I am using a null Layout Manager) I want component A to be displayed on top of component B when I add it. I have a JLabel which I am trying to drag over a bunch of JTextFields, but right now the Label shows up behind all the JTextFields instead of on top when it is being dragged.

  • CS6 "Combine" button gone

    Pre-CS6 there was a "Combine" button when you used the Path Selection Tool (A) to select multiple shapes within the same layer.
    How does one accomplish said action now that the combine button is gone? Merging two layers has not got the same effect.
    Please tell me I'm not going to have to go back to CS5 to use this feature
    Cheers,
    - Dirk

    And guess what »photoshop_reference.pdf« states on p.469?
    Merge overlapping path components
    1. Select the path name in the Paths panel, and select the Path Selection tool .
    2. Click Combine in the options bar to create a single component from all overlapping components.
    Merging the documentation for CS5 and CS6 seems to have been poor decision …

Maybe you are looking for

  • Installation error sap 4.7

    hi all, i got installation problem while installing sap 4.7 on my pc the error is , INFO 2008-03-21 00:03:16 Processing of host operation t_HostInfo_SHARED succeeded. INFO 2008-03-21 00:03:25 The 'saploc' share exists at directory 'F:\usr\sap'. Choos

  • ALE distribution of planned material changes made using MM12

    Greetings, I have searched and come up empty-handed looking for an answer, perhaps someone in this forum can point me in the right direction.  I am trying to find out if there is a tcode and idoc message type that will distribute a planned material c

  • ITunes only syncs part of a playlist

    I have a iphone 4 running ios 5.0.1 and itunes 10.5.3 on a new macbook, and I can not get playlists to sync to my phone.  It only transfers 6 songs per playlist.  I don't want to have to restore my phone. Is there any other way? What am I missing?

  • Forum login problem

    Why do I Have to login every tim I visit the forum? Is it just me? I have a slow internet connection and it's really a pain in the ass!

  • Competition for the best apex-site ?

    Hi, can a competition be started for the best apex-site ? choosen by visitors of this forum. once a year (for example). Leo