Moving JPanel in JLayeredPane

Hello!
I'm tryiing to make information board which retrieve data from DB and shows the data graphically at the applet.
Thus, I made some indicators,which extends JPanel, and put them on JLayeredPane. the data also have position information and if the position is changed and a position of indicator should be changed.
However, I couldn't make it move at the layeredPane.
I used setBounds, setLocation, repaint, revalidate with all possible cases, but failed too. :-(
Here is my code...
any comments or help would be appreciated.
<code>
import javax.swing.*;
import org.jdom.Element;
import java.awt.*;
import java.util.List;
import java.util.Vector;
public class CenterPanel2 extends JPanel{
     private JLayeredPane layeredPane;
     private JPanel backImage;
     //width and height of background image panel(backImage)
     private int width, height;
     private Vector indicators;
     public CenterPanel2(List parts){
          //Create and set the layeredPane property
          this.layeredPane = new JLayeredPane();
          this.layeredPane.setOpaque(false);
          this.setBackground( Color.lightGray );
//draw the background image
          backImage = new PanelBackImage();
          width = (int)backImage.getPreferredSize().getWidth();
          height = (int)backImage.getPreferredSize().getHeight();
//set layeredPane and add image
this.layeredPane.setPreferredSize ( new Dimension( width+20, height+20) );
//bottommost layer
this.layeredPane.add(backImage, JLayeredPane.DEFAULT_LAYER);
backImage.setBounds(0, 0, width, height);
//make vector to store indicators
indicators = new Vector();
     for (int i = 0; i < parts.size(); i++) {
          Element epart = (Element)parts.get(i);
          PART part = new PART(epart);
          String type = part.getType();
          int x = part.getPositionX();
          int y = part.getPositionY();
          int id = part.getId();
          if( type.equals("A")){
               Indicator a = new AType(x,y);
               a.setID(id);
               indicators.addElement(a);
          else if( type.equals("B")){
               Indicator b = new BType(x,y);
               b.setID(id);
               indicators.addElement(b);
          else {}//do dothing
     }//for
     //add to layeredPane
          for(int i = 0; i<indicators.size();i++){
               JPanel tmp = (JPanel) indicators.get(i);
               //add to the second mostbottom layer
               tmp.setBounds(tmp.getX(), tmp.getY(), 100, 100);
               this.layeredPane.add(tmp, JLayeredPane.PALETTE_LAYER);
//finally add layeredpane to this
this.add(layeredPane);
     }//CenterPanel()
///this is called my JApplet update()
     public void updatePanel(List parts){
          System.out.println("centerpanel2: updatePanel has been called!");
          for(int i=0; i<parts.size();i++){
               Element epart = (Element)parts.get(i);
               PART part = new PART(epart);
               int id = part.getId();
               int x = part.getPositionX();
               int y = part.getPositionY();
               Rectangle tmpRec = new Rectangle(x, y, 100, 100);
               for(int j=0;j<indicators.size();j++){
                    Indicator tmp = (Indicator)indicators.get(j);
                    JPanel jtmp = (JPanel) tmp;
                    //if ID is same and position was changed move panel
                    if(id == tmp.getID() && !tmpRec.equals(jtmp.getBounds())){
                         jtmp.setBounds(x,y,100,100);
               }//inner for
          }//out for
     }//update
}//end of centerPanle class
</code>

what you could do is create a sligtly smaller Panel that held a JLabel that was really small and the pull down meny and then add that as one alowing you to move stuff by grabing the JLabel which dosn't even have to have text.

Similar Messages

  • Layering a series of Transparent images onto a JPanel or JLayeredPane

    Hello all -
    I am working on creating a viewfinder type component for a game engine I am developing. Currently, I am loading a BackBuffered image from an array and displaying it in a JPanel. This image essentially serves as the "background" of the viewfinder.
    What I would like to do is go one step further and after the background image is determined, load a series of transparent images and place those on top of the background, BEFORE the repaint() method is called. An example of this would be loading the background image, and then loading walls (or other sprites), firing the repaint() method, resulting in the rendering all the images at one time.
    I have looked into JLayeredPane, but am uncertain as to whether this is the correct avenue to pursue. Does anyone have any experience with this?
    Any assistance would be greatly appreciated.

    JLayeredPane is not the way to go. Just draw your images on a panel. If you want/need to do all the drawing before repainting, use a back buffer. See BufferedImage

  • DnD JPanel and show moving JPanel

    I have JPanels on a JFrame and want the user to be able to drag a JPanel to a different part, which is easy with Drag and Drop, but
    Is it possible to show the JPanel moving along with the mouse?
    Or is it at least possible to show some text dragging along with the mouse?

    Write your own "DnD" code. Something like this:
    http://forum.java.sun.com/thread.jspa?forumID=57&threadID=599181

  • From JPanel to JLayeredPane

    Hi all, I'm having some trouble with something I though it would be easier...
    I had a JApplet with a main JPanel I added directly to the contentPane, and worked ok, something like...
    JPanel jpan = functionThatCreatesJPanel();
    Container contentPane = getContentPane();
    contentPane.add(jpan);... but now, I need to display some screens over this panel, so I was thinking in using a JLayeredPane, add the old JPanel as background layer, and add new JPanels over it. Is this idea correct?
    JLayeredPane lp = new JLayeredPane();
    lp.setPreferredSize(new Dimension(975,575));
    lp.add(functionThatCreatesJPanel(),new Integer(1));
    lp.setVisible(true);
    Container contentPane = getContentPane();
    contentPane.add(lp);and my applet stays gray! no error messages are shown...
    what do you think?
    thanks!

    Well, this might be a little late to help you, but I was experiencing the same problem. I solved it by adding a component listener on the layered pane that relayed resize events to the contained JPanel, like so:
    layeredPane.addComponentListener(new java.awt.event.ComponentAdapter() {
                public void componentResized(java.awt.event.ComponentEvent evt) {
                     backgroundPanel.setSize(layeredPane.getSize());
            });This appears to correctly paint the panel.

  • How to put a Jpanel always over a JtextArea ?

    I want to have a little Jpanel above a JTextArea.
    At the initialize section, I add first the Jpanel and after the JtextArea (both in a 'parent' Jpanel with null layout)
    When I run the program I see the Jpanel over the JtextArea, but when I write on it and it reaches the area when the Jpanel is placed, the JtexArea brings to front and the Jpanel is no longer visible.
    So, how can I have my Jpanel on top always ?
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)
    Thanks
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)

    tonnot wrote:
    And another question , is there a hierarchy that control that I Jpanel is always over a Jbutton (even if the initial z-order of the button is higher than the Jpanel's)JLayeredPane
    ( I do not send any code because it is so simple as putting this two components into a Jpanel)Try it with a JLayeredPane and if you still have problems, post a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://mindprod.com/jgloss/sscce.html].
    db

  • How to repaint a component when it moves?

    Hello, I have an application with many JPanels packed together, and one of them has a picture that I render with the paint() method, using the coordinates of the panel as reference. For example, suppose I were to draw the diagonal:
    Dimension d = getSize();
    int w = d.width;
    int h = d.height;
    g.clearRect(0, 0, w, h);
    g.drawLine(0, 0, d.width - 1, d.height - 1);Now on events of user input, the size of other components may change and I revalidate the root pane. This may move or resize my JPanel where I drew.
    So I thought paint() would automatically be called if the component is moved. But it's not! the JPanel moves around, with the diagonal staying in its old place on the screen (so it is no longer the diagonal of the moved JPanel).
    Why and How to do this properly?      It would not be easy, if the user changes any of the many components, to have to manually keep track of everything else and repaint() everything else on the account that it might move, or have to compute whether it moved and repaint(). Wouldn't I be doing the job of the layout manager then? (I use many nested GridBag Layout managers).
    Thank you for any insight. Mark

    For example:
    import java.awt.Color;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.event.MouseAdapter;
    import java.awt.event.MouseEvent;
    import java.awt.image.BufferedImage;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.imageio.ImageIO;
    import javax.swing.JFrame;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JComponent;
    * @version 1.0, 11/13/2008
    * @author Pete
    * Image from Funny Junk website: http://www.funnyjunk.com/funny_pictures/
    public class MovePicPanel
      private static final Dimension PANEL_SIZE = new Dimension(800, 700);
      private JPanel mainPanel = new JPanel();
      private BufferedImage image;
      private JPanel picPanel = new JPanel()
        protected void paintComponent(Graphics g)
          super.paintComponent(g);
          if (image != null)
            //!! here's where I draw my image in the JPanel
            g.drawImage(image, 0, 0, this);
      public MovePicPanel()
        try
          image  = ImageIO.read(new URL("http://newmedia.funnyjunk.com/pictures/bills-in-context.jpg"));
        catch (MalformedURLException e)
          e.printStackTrace();
        catch (IOException e)
          e.printStackTrace();
        if (image != null)
          int width = image.getWidth();
          int height = image.getHeight();
          picPanel.setSize(new Dimension(width, height));
          picPanel.setLocation(0, 0);
        JLabel clickMeLabel = new JLabel("Click me and drag mouse");
        clickMeLabel.setFont(clickMeLabel.getFont().deriveFont(Font.BOLD, 32));
        clickMeLabel.setForeground(Color.red);
        picPanel.add(clickMeLabel);
        MouseAdapter mouseAdapter = new MyMouseAdapter();
        mainPanel.addMouseListener(mouseAdapter);
        mainPanel.addMouseMotionListener(mouseAdapter);
        mainPanel.setPreferredSize(PANEL_SIZE);
        mainPanel.setLayout(null);
        mainPanel.add(picPanel);
      public JComponent getComponent()
        return mainPanel;
      private class MyMouseAdapter extends MouseAdapter
        @Override
        public void mousePressed(MouseEvent e)
          picPanel.setLocation(e.getPoint());
        @Override
        public void mouseDragged(MouseEvent e)
          picPanel.setLocation(e.getPoint());
      private static void createAndShowUI()
        JFrame frame = new JFrame("MovePicPanel");
        frame.getContentPane().add(new MovePicPanel().getComponent());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }

  • Damn peculiar bug -- transferring JComponent from one place to another

    I have a JSplitPlane, which has a JTree in the left side and the right side gets a JPanel depending on what is selected in the JTree. This works great.
    Although this is probably not relevant, I also save the non-selected JPanels so they aren't re-created again when selected again. That works great too.
    So next I implemented a "tear off function," where I take the currently displayed JPanel and create a new JFrame to put it in. This allows the user to display any number of panels. This also seems to work. Here is the code that does it:
      public void tearOffPanel() {
            JComponent component = (JComponent) splitPlane.getRightComponent();
            if (component == null || component == hitherePanel) return;
            // if component is already torn off, ignore ths
            if (tornOff.containsKey(component)) return;
            // create a new frame
            splitPlane.setRightComponent(hitherePanel);
            JFrame frame = new JFrame();
            frame.setTitle(modelTree.getSelectionPath().getLastPathComponent().toString());
            frame.getRootPane().setLayout(new BorderLayout());
            frame.setLocationRelativeTo(getFrame());
            frame.setSize(component.getSize());
            frame.getRootPane().add(component, BorderLayout.CENTER);
            frame.addWindowStateListener(this);
            frame.setVisible(true);
            // add to torn off map
            tornOff.put(component, frame);
        }What goes wrong is some of the Swing controls in the moved JPanel don't work right after the move. If have some radio buttons -- they work fine. I have some ComboBoxes -- they work if you use keystrokes but they no longer show their popup window and you can't operate them with the mouse. You can focus on them with the mouse and change the selection with the keyboard.
    Any ideas on why this could be? I'm stumped.

    I'm curious why you are adding things to the rootpane and not the contentPane.
    I have no idea if this can cause problems, but it seems atypical to me in the very least.The reason is because I blew it -- I picked the wrong option on auto-complete in netbeans. As I mentioned I am not that familiar with Swing (learning more every day) and these days MOST of this code is auto-generated for you so this kind of mistake doesn't often occur.
    The answer is yes it does cause the problem. When I changed the add from RootPane to ContentPane the problem went away.
    As you posted I was able to re-create the problem with an example I was about to post. The interesting thing about it is that it does not come up in a generalized way -- if I move the JComponent from the right side of a splitPlane to a new JFrame it CAN happen -- if I move it from a JPanel it doesn't. Further, in my test case it only happens if you resize the source frame before you do the move. Something subtle is going on there but I can ignore it now since using the correct target pane causes no problems.
    Thanks for your help.

  • BlackjackGame

    Hi,
    For one of my college classes I volunteered to change a gui line blackjack program to a gui based on swing. This is my first time actually creating something useful with swing so my code probably sucks but it works for the most part.
    heres my problem...
    the cards are loaded onto the frame first by the GUIGame which makes a call to my addCard class and either executing one of the following methods, addCardDealer or addCardPlayer. My problem is that I have no idea how to load images and what would be the best way of loading my card images on to the screen.
    here is the relivant code that i'm working with...
    package blackjackpackage;
    * @author villajo
    public class GUIGame
    public void playGUI()
    BlackJackGUI GUI = new BlackJackGUI();
    addCard add = new addCard();
    //Instantiates our deck of cards object. Constructor builds the arraylist of Card Objects.
    Deck gameDeck = new Deck();
    Hand playerHand = new Hand();
    Hand dealerHand = new Hand();
    boolean continueGame = true;
    gameDeck.shuffle();
    //playerHand.add(gameDeck.draw());
    GUI.add(add.addCardPlayer(gameDeck.draw()));
    GUI.add(add.addCardDealer(gameDeck.draw()));
    GUI.add(add.addCardPlayer(gameDeck.draw()));
    GUI.add(add.addCardDealer(gameDeck.draw()));
    This is the BlackjackGUI. This is responsable for the buttons, menus, action handlers and anything that has to do with the BlackjackGUI..(I know that there aren't action handlers yet for the buttons.. thats coming in time..)
    * BlackJackGUI.java
    * Created on June 22, 2007, 10:38 AM
    * To change this template, choose Tools | Template Manager
    * and open the template in the editor.
    package blackjackpackage;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    * @author villajo
    public class BlackJackGUI extends JFrame
    /** Creates a new instance of BlackJackGUI */
    public BlackJackGUI()
    /*finds screenheight and width and sets the program to center.
    int screenHeight;
    int screenWidth;
    FindScreenSize screen = new FindScreenSize();
    screenHeight = screen.returnHeight();
    screenWidth = screen.returnWidth();
    setLocation(screenWidth / 4, screenHeight / 4);
    //create our JFrame
    setTitle("BlackJack");
    setSize(DEFAULT_WIDTH,DEFAULT_HEIGHT);
    //this makes it so we CANNOT resize the window
    setResizable(false);
    //all menu stuff..
    BlackJackMenuBar MenuBar = new BlackJackMenuBar();
    BlackJackButtons buttons = new BlackJackButtons();
    add(buttons);
    setVisible(true);
    class BlackJackMenuBar
    protected BlackJackMenuBar()
    JMenu File = new JMenu("File");
    JMenu About = new JMenu("About");
    //File menu attributes..
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    //adding the menus..
    menuBar.add(File);
    menuBar.add(About);
    //adding functions to menubar..
    File.addSeparator();
    File.add(new AbstractAction("Exit")
    public void actionPerformed(ActionEvent event)
    System.exit(0);
    About.add(
    new AbstractAction("About")
    public void actionPerformed(ActionEvent event)
    aboutWindow about = new aboutWindow();
    class addCard extends JPanel
    private static final int DEFAULT_WIDTH = 640;
    private static final int DEFAULT_HEIGHT = 480;
    public int playerScore = 0;
    public int dealerScore = 0;
    class BlackJackButtons extends JPanel
    public BlackJackButtons()
    BlackjackGame game = new BlackjackGame();
    JButton Hit = new JButton("Hit");
    JButton Stand = new JButton("Stand");
    //JButton Smack = new JButton("Smack");
    //adding the cute java image..
    setLayout(null);
    add(Hit);
    add(Stand);
    //add(Smack);
    Insets buttonInsets = getInsets();
    Dimension size = Stand.getPreferredSize();
    Hit.setBounds(220 + buttonInsets.left, 385 + buttonInsets.bottom, size.width, size.height);
    Stand.setBounds(310 + buttonInsets.left, 385 + buttonInsets.bottom, size.width, size.height);
    //Jpanel S
    //add action Listeners...
    //add JLabels
    //pastes our label on the panel..
    PlayerMessage player = new PlayerMessage();
    DealerMessage dealer = new DealerMessage();
    add(player);
    add(dealer);
    Insets playerInsets = getInsets();
    Insets dealerInsets = getInsets();
    Dimension dealerSize = dealer.getPreferredSize();
    Dimension playerSize = player.getPreferredSize();
    player.setBounds(15 + playerInsets.left, 80 + playerInsets.bottom, playerSize.width, playerSize.height);
    dealer.setBounds(15 + dealerInsets.left, 205 + dealerInsets.bottom, dealerSize.width, dealerSize.height);
    class PlayerMessage extends JPanel
    public PlayerMessage()
    JLabel player = new JLabel("Player:");
    add(player);
    class DealerMessage extends JPanel
    public DealerMessage()
    JLabel dealer = new JLabel("Dealer:");
    add(dealer);
    class addImage extends JLabel
    public void addImage(String card)
    //retrieve the card from the file of cards..
    ImageIcon icon = new ImageIcon("/home/villajo/blackjackPackage/src/blackjackpackage/Cards/" + card);
    icon.getImage();
    //this determines the bounds or the placement of the cards..
    class addCard extends JPanel
    public JLayeredPane addCardPlayer(Card card)
    *What i'm doing is finding the deck and tally so that I can put it on screen..
    //This finds the card and the score for that card and adds it to player..
    GUIHelper findNumber = new GUIHelper();
    int localScore = findNumber.WhatScoreAmI(card);
    String cardtype = card.toString() + ".jpg";
    //Load the appropriate Image..
    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(76,110));
    ImageIcon img = new ImageIcon(cardtype);
    img.getImage();
    JLabel label = new JLabel(img);
    layeredPane.add(label);
    return layeredPane;
    public JLayeredPane addCardDealer(Card card)
    GUIHelper findNumber = new GUIHelper();
    int localScore = findNumber.WhatScoreAmI(card);
    String cardtype = card.toString() + ".jpg";
    System.out.println(cardtype);
    //load the appropriate image..
    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(76,110));
    ImageIcon img = new ImageIcon(cardtype);
    img.getImage();
    JLabel label = new JLabel(img);
    layeredPane.add(label);
    return layeredPane;
    I know that I dont have the bounds set or any of the properties set up, I'm just wanting it to load up and from there I think I can figure it out. Some other information, the images are of JPG format and are located in the source file where all of the other sources and classes are located for the project.
    addCard class handles the adding of cards to new layers of the LayeredPanel. I thought this might be easier if I used a layered pane instead of adding a new JPanel.
    card takes in a card from another class called card but is passed through GUIgame to addCard. This is probably bad design practice, but i'm just trying to get it to work. What card does is takes a shuffled deck of cards and takes a card from it.
    thanks in advance for any help
    Joseph Villa

    I've used code like the following to load small images/icons for display:
        private static ImageIcon createImageIcon(String path) {
            if (path != null) {
                URL imgURL = MyMainClass.class.getResource(path);
                if (imgURL != null) {
                    return new ImageIcon(imgURL);
                } else {
                    log.error("Couldn't find file: " + path);
                    return null;
            } else {
                log.error("Cannot search for null image file.");
                return null;
        }which gets invoked with something like:
        public static final ImageIcon ICON_EXPAND_ALL = createImageIcon("/images/expandAll.gif");Note the path passed to the method is the path within the jarfile holding the application (which is what I think you meant in your problem description).
    Naturally, if you're loading a lot of images, you should move that code into a distinct thread, so the application doesn't seem to hang while loading them.
    Message was edited by:
    mbmerrill - to change name of main class to make it clear that it is, in fact, the main class

  • Selecting a portion of a JComponent

    Hi,
    I need to provide the ability for a user to select a portion of a JComponent. My final aim is to obtain the Rectangle coordinates for the selection, but while selecting, the user should be able to see a box around the selection area as he is dragging his mouse while selecting. How can I go about doing this?
    Thanks.

    OK, I get the point, but I'm still unclear on how my classes will need to be structured. Here's how I would like it to be:
    I have a class A in which I create my JFrame, and add several other components such as JPanel, JButton, JLayeredPane etc etc to the frame. Then, from class A, all I would want to do is call B b = new B(component), where component can be anything that's been added to my JFrame.
    Now, the B class would really be the selection utility class, in which I do all the required initialization, look for mouse events and mouse motion events, and draw the box around the selected area of the component in question. Now since this B class is just a utility class, I can't really make it extend the component class so that I can write my own paintComponent method.
    Am I making sense? If you could please provide some basic code outline/structure on how to arrange my classes, that's be very helpful.
    Thanks.

  • Jpanel is moving, not fix

    Hi there, i am making a swing appl. and there is a jpanel on my window. On jpanel there is a jlabel. When i run application my panel is movind 2-3 mm to the right side. While application is working a few minutes later the jpanel is turning back the its original place. Because of panel is moving other components at the right of panel is moving as panel. I unchecked all resizables but didnt work.
    I coundt find why it is happining? can anyone have idea?
    Thanks all.

    Your problem IS the NetBeans visual designer, which generates code you can't understand (most of which I don't understand [or even try to understand] either). Learn layouts and do the job correctly.
    I have lots of things have to do parallel at same time. 10 days i am in trouble with this.
    Teacher: Why are you late for school?
    Student: Please sir, I started late from home.
    Teacher: So why didn't you start early?
    Student: Please sir, it was too late to start early.
    Already i handled my problem.No, you just deferred it to the next time. When you'll be back here with the same unsmart questions about something you simply neglected to learn the right way.
    I wish you luck in life. You'll need it.
    db

  • Overlapping two JPanels on a JLayeredPane

    I am having some problems overlapping two JPanels on a JLayeredPane for some reason only one of them shows when I compile the program! Any help would be greatly appreciated
    The code is the following:
    import java.lang.*;
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SpaceBall
    //To do the background just draw a JPanel inside another //JPanel just set the opacity of the outside one
    //to false and let
    //it hold all the components of the game
    public static void main(String[] args)
    //declaring the buttons
    JButton test=new JButton("test");
    JButton test1=new JButton("test1");
    JButton test2=new JButton("test2");
    //declaring and setting the properties of the frame
    JFrame SpaceBall= new JFrame("Space Ball");
    SpaceBall.setSize(700,650);
    //declaring the Panels
    JLayeredPane bgPanel= new JLayeredPane();
    JPanel fgPanel= new JPanel();
    JPanel topPanel= new JPanel();
    JPanel sidePanel= new JPanel();
    JPanel lowPanel= new JPanel();
    JPanel masterPanel= new JPanel();
    //adding the buttons to the corresponding panels
    fgPanel.add(test1);
    sidePanel.add(test2);
    topPanel.add(test);
    ImageIcon background= new ImageIcon("images/background.jpg");
    JLabel backlabel = new JLabel(background);
    backlabel.setBounds(0,0,background.getIconWidth(),background.getIconHeight());
    backlabel.add(test1);
    bgPanel.add(backlabel, new Integer(0));
    fgPanel.setOpaque(false);
    bgPanel.add(fgPanel, new Integer(100));
    bgPanel.moveToFront(fgPanel);
    //adding bgPanel and sidePanel to lowPanel
    lowPanel.setLayout(new GridLayout(1,2));
    lowPanel.add(bgPanel);
    lowPanel.add(sidePanel);
    //adding the Panels to the masterPanel
    masterPanel.setLayout(new GridLayout(2,1));
    masterPanel.add(topPanel);
    masterPanel.add(lowPanel);
    //getting the container of SpaceBall and adding the Panels to it
    Container cp=SpaceBall.getContentPane();
    cp.add(masterPanel);
    //displaying everything
    SpaceBall.show();
    WindowListener ClosingTheWindow=new WindowAdapter()
    public void windowClosing(WindowEvent e)
    System.exit(0);
    SpaceBall.addWindowListener(ClosingTheWindow);

    Take a look at the section from the Swing tutorial titled "How to Use Layered Panes". It has a sample program:
    http://java.sun.com/docs/books/tutorial/uiswing/components/layeredpane.html

  • Moving a JLayeredPane, fluently.

    I have the following code which represents a minimap with a frame around that i want to be able to drag around the screen.
    The dragging function is working, however not as prcise as i wanted it to be, but thats not my problem.
    The problem i have is that it looks extremly laggy and it dosent move fluently AT ALL. more like Java redraws the layer every second.
    Is this even possible to do? (performance wise) And how then?
    Any comments regarding my use of constructor and paint method is welcome. I mostly always get the program working yet i never quite know what is "good" and "bad" programming.
    Thanks in advance.
    K.
    import java.awt.*;
    import java.io.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.awt.geom.*;
    import java.awt.event.MouseMotionListener;
    import java.awt.event.MouseEvent;
    public class dragableBorder extends JPanel implements MouseListener, MouseMotionListener
    private HexagonMap map;
    private JLabel headText;
    public dragableBorder(Hexagon[][] contents,TexturePaint[] textureMap)
    map=new HexagonMap(false, contents, textureMap);
    this.setBorder(BorderFactory.createLineBorder(Color.black,2));
    this.setLayout(new BorderLayout());
    this.add(map,BorderLayout.CENTER);
    headText = new JLabel("Minimap");
    headText.setOpaque(true);
    headText.setBackground(Color.black);
    headText.setForeground(Color.white);
    headText.setBounds(0, 0, 140,0);
    headText.addMouseListener(this);
    headText.addMouseMotionListener(this);
    this.add(headText,BorderLayout.NORTH);
    this.setVisible(true);
    public void paintComponent(Graphics g)
    Graphics2D g2d=(Graphics2D) g;
    clear(g);
    protected void clear(Graphics g)
    super.paintComponent(g);
    [Deleted a bunch of not used mouseactions]
    public void mouseDragged(MouseEvent e)
    this.setLocation(e.getX()+this.getX(),e.getY()+this.getY());
    repaint();
    }

    When I work with a drive to boot many computers, I use the newest model computer I will be booting, and set the system up on that, run all the Apple updates. Normally I will have no issue booting any older computer with the same drive. Unless of course those older computers do not support the operating system on that drive.
    If you want to test if the drive will boot the mac mini. Put your MacBook Pro into target mode. Connect the two computers together. And on the Mac Mini, go into system preferences and then under start up disk and see if the target disk mode computer's drive shows up there. Seelct that drive and restart. See if it boots ok. A bit easier then taking the drives out and moving things around.

  • How to moving image or graphic on the JPanel??

    Hi,
    Everybody got any idea to do using mouse listener to click and moving the image or graphic and then to put the object at any coordinate on the JPanel???
    Thank to reply..

    You don't
    You cannot use other countries itunes stores.
    Sorry

  • Hot to get components to adjust size & fill Jpanel when splitPane is moved

    HI, i am developing a small app that makes heavy use of swing. in the main JFrame, i need to have a a horizontal split bar dividing it into a top and a bottom
    area and in the bottom area another vertical one diving it into 2, left and right. in the right area i need to put a lot of visual controls such as labels, textboxes....
    the thing is that i need them to stretch and shrink in size everytime the splitpane is moved. i use a JPanel to hold these controls.
    how can it be done?
    thank you

    DarrylBurke wrote:
    _steve wrote:
    i know how to use layout managers i just don't know which yields the desired behavior, the one i want.Hence the nudge towards the relevant tutorial, where you can find what you need to know.
    i am not an expert swing developer and i don't intend to become one today.Ah, ok. Good luck finding another job, then.
    thank youYou're welcome, I'm sure.
    dbthank yourself, typical. if you don't have any positive input to contribute with, please do not enter the discussion and save yourself the frustration.
    not having time, not needing swing is something and not willing to work is something else.you are no better developer, that i am sure of, too.

  • Cursor setting when having several JPanel in a JLayeredPane

    Hello,
    I have placed two JPanel in different layers of a JLayeredPane.
    The lower panel sets cursors on several objects. When only this panel is in the JLayeredPane the cursors are shown ok.
    But when I placed a second JPanel (transparent of course) above the 1st one the cursors are not set. Everything seem to be the same in the lower panel but for the cursors.
    Any clue why this is so?
    Thanks.

    I am running across lot of "weird" things in javaSounds like your code is wierd.
    like when changing an attribute in a JTexPane and it only works for
    the next two characters you type then the default attribute is magically reset back to default.Never had a problem. Read the JTextPane API. You will find a link to the Swing tutorial on 'Using Text Components" which has a working example of setting attributes.
    Don't blame Java for your lack of understanding!
    Also so the JTextPane is not editable you still can select text with the mouse which doesn't make any senseSure it does. I can select and copy any text from this web page even though it isn't editable.
    "editable" means you can't type into the text component. It doesn't say "uncopyable".
    So don't editorialize your comments. Just state what you are trying to accomplish.

Maybe you are looking for

  • Web Part is not visible in Web Part gallary

    Hi, I have developed a project in sharepoint having two web parts inside it. Initially, when there was only one web part in my project it was working fine. But suddenly when i added a new web part, it is not showing me web parts in a gallary. Event i

  • FBL3N: reason code display

    Hi guys I'd like to add reason code to the selection screen of FBL3N. But it isn't displayed in the list available. While it is in the list available of FBL1N. How can I make it selectable on screen FBL3N? Should I config something in O7F8? how to do

  • The Case of the Disappearing Clones

    Ok, here's a new one for me. I was cloning a cloud edge, and examining my work. The History palette was blocking my view, so I moved it. Instead, it jumped to the palette bar. Brought it back and tried to move it again. Same thing. Huh? I opened it f

  • Why can't i save the same bookmarks in different locations?

    Why can't I save a bookmark for a particular site in multiple locations? If I already have it saved, for instance, in the bookmarks menu, and I then try to save an additional copy into the bookmarks folder, the copy in the bookmarks menu will disappe

  • Log4j in all pages

    I am trying to use log4j for the first time should I instantiate a static logger globally ? or have a Logger logger = Logger.getLogger(MyServlet.class); for every class and jsp page? The former makes sense... I am not sure how I can achieve that thou