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

Similar Messages

  • 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.

  • Setting Up a GUI - FlowLayout - Using Two JPanels

    Hello:
    I am getting confused with setting up a GUI with two JPanels one that would be on top and the other middlePanel having a FlowLayout.
    I set up two JPanels but obviously have something wrong because my northPanel has "disappeared" when I added a middlePanel. My componets are all over the place and again my northPanel is no longer showing.
    Idea of what I'm doing.
    1) Enter total number of diners
    2)Confirm that diners # is correct.
    3)Enter name of Diner
    4)Take order - Entree (Pull-Down)
    5)Two sides (CheckBox)
    6)Display Completed Order of diners.
    P.S. I hope my question is not too stupid I am new and has justed started Java Programming. I have tried to look through the Documentation but am getting confused with GUI relating to FlowLayout, GridLayout. etc. I'm just not sure which one I should use to set up my GUI in an organized manner. Am I on the right track or is my code completely screwed. Thanks.
    ** My Code **
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Menu extends JFrame {
    private JTextField partyNumField, dinerName;
    private JComboBox orderComboBox;
    private int partyNum;
    private JButton getParty, continueOrder;
    private JLabel party, companyLogo, dinerLabel, entreeOrder;
    private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
    private JCheckBox mashed, cole, baked, french;
    public Menu() {
    super("O'Brien Caterer - Where we make good Eats!");
    Container container = getContentPane();
    JPanel northPanel = new JPanel();
    northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 80, 5));
    companyLogo = new JLabel("Welcome to O'Brien's Caterer's");
    northPanel.add(companyLogo);
    party = new JLabel("Enter the Total Number in Party Please");
    partyNumField = new JTextField(5);
    northPanel.add(party);
    northPanel.add(partyNumField);
    getParty = new JButton("GO - Continue with Order");
    getParty.addActionListener(
    new ActionListener(){
    public void actionPerformed(ActionEvent actionEvent)
    partyNum = Integer.parseInt(partyNumField.getText());
    String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
    + partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
    + "Enter 2 to cancel\n");
    if (ans.equals("1")) {
    System.out.println(ans+"=continue"); // handle continue
    } else { // assume to be 2 for cancel
    System.out.println(ans+"=cancel"); // handle cancel
    ); // end Listener
    northPanel.add(getParty);
    JPanel middlePanel = new JPanel();
    middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
    dinerLabel = new JLabel("Please enter Diner's name");
    dinerName = new JTextField(30);
    continueOrder = new JButton("continue");
    middlePanel.add(dinerLabel);
    middlePanel.add(continueOrder);
    middlePanel.add(dinerName);
    entreeOrder = new JLabel("Please choose an entree");
    orderComboBox = new JComboBox(dinnerEntree);
    orderComboBox.setMaximumRowCount(4);
    //orderComboBox.addItemListener(
    // new ItemListener(){
    // public void itemsStateChanged(ItemEvent event)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // add entree order to Person
    // continue ** enable the two sides order
    mashed = new JCheckBox("Mashed Potatoes");
    middlePanel.add(mashed);
    cole = new JCheckBox("Cole Slaw");
    middlePanel.add(cole);
    baked = new JCheckBox("Baked Beans");
    middlePanel.add(baked);
    french = new JCheckBox("FrenchFries");
    middlePanel.add(french);
    // CheckBoxHandler handler = new CheckBoxHandler();
    // mashed.addItemListener(handler);
    // cole.addItemListener(handler);
    // baked.addItemListener(handler);
    // french.addItemListener(handler);
    middlePanel.add(entreeOrder);
    middlePanel.add(orderComboBox);
    container.add(northPanel);
    container.add(middlePanel);
    middlePanel.setEnabled(true);
    setSize(500, 500);
    show();
    // private class to handle event of choosing Check BOx Item
    // private class CheckBoxHandler implements ItemListener{
    // private int count = 0;
    // public void itemStateChanged(ItemEvent event){
    // if (event.getsource() == mashed)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    // add mashed choice to person's order
    // if (event.getsource() == cole)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add cole slaw to person's order
    // if (event.getsource() == baked)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add baked beans to person's order
    // if (event.getsource() == french)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add french to person's order
    public static void main(String args[])
    Menu application = new Menu();
    application.addWindowListener(
    new WindowAdapter(){
    public void windowClosing(WindowEvent windowEvent)
    System.exit(0);
    }

    This looks better, i myself don't like the flow layout
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Menu1 extends JFrame
         private JTextField partyNumField, dinerName;
         private JComboBox orderComboBox;
         private int partyNum;
         private JButton getParty, continueOrder;
         private JLabel party, companyLogo, dinerLabel, entreeOrder;
         private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
         private JCheckBox mashed, cole, baked, french;
    public Menu1()
         super("O'Brien Caterer - Where we make good Eats!");
         addWindowListener(new WindowAdapter()
             public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         Container container = getContentPane();
         JPanel northPanel = new JPanel();
         northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120,15));
         companyLogo   = new JLabel("Welcome to O'Brien's Caterer's");
         northPanel.add(companyLogo);
         party         = new JLabel("Enter the Total Number in Party Please");
         partyNumField = new JTextField(5);
         northPanel.add(party);
         northPanel.add(partyNumField);
         getParty    = new JButton("GO - Continue with Order");
         northPanel.add(getParty);
         northPanel.setPreferredSize(new Dimension(700,150));
         getParty.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent actionEvent)
                   partyNum = Integer.parseInt(partyNumField.getText());
                   String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
                   + partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
                   + "Enter 2 to cancel\n");
                   if (ans.equals("1"))
                        System.out.println(ans+"=continue"); // handle continue
                   else { // assume to be 2 for cancel
                   System.out.println(ans+"=cancel"); // handle cancel
         }}); // end Listener
         JPanel middlePanel = new JPanel();
         middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         dinerLabel         = new JLabel("Please enter Diner's name");
         dinerName          = new JTextField(30);
         continueOrder      = new JButton("continue");
         middlePanel.add(dinerLabel);
         middlePanel.add(dinerName);
         middlePanel.add(continueOrder);
         entreeOrder   = new JLabel("Please choose an entree");
         orderComboBox = new JComboBox(dinnerEntree);
         orderComboBox.setMaximumRowCount(4);
    //orderComboBox.addItemListener(
    // new ItemListener(){
    // public void itemsStateChanged(ItemEvent event)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // add entree order to Person
    // continue ** enable the two sides order
         mashed = new JCheckBox("Mashed Potatoes");
         middlePanel.add(mashed);
         cole   = new JCheckBox("Cole Slaw");
         middlePanel.add(cole);
         baked  = new JCheckBox("Baked Beans");
         middlePanel.add(baked);
         french = new JCheckBox("FrenchFries");
         middlePanel.add(french);
    // CheckBoxHandler handler = new CheckBoxHandler();
    // mashed.addItemListener(handler);
    // cole.addItemListener(handler);
    // baked.addItemListener(handler);
    // french.addItemListener(handler);
         middlePanel.add(entreeOrder);
         middlePanel.add(orderComboBox);
    //container.add(northPanel);
    //container.add(middlePanel);
         container.add(northPanel, java.awt.BorderLayout.NORTH);
         container.add(middlePanel, java.awt.BorderLayout.CENTER);
         middlePanel.setEnabled(true);
         setSize(600, 500);
         show();
    // private class to handle event of choosing Check BOx Item
    // private class CheckBoxHandler implements ItemListener{
    // private int count = 0;
    // public void itemStateChanged(ItemEvent event){
    // if (event.getsource() == mashed)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    // add mashed choice to person's order
    // if (event.getsource() == cole)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add cole slaw to person's order
    // if (event.getsource() == baked)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add baked beans to person's order
    // if (event.getsource() == french)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add french to person's order
    public static void main(String args[])
         new Menu1();
    no edit
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Menu1 extends JFrame
         private JTextField partyNumField, dinerName;
         private JComboBox orderComboBox;
         private int partyNum;
         private JButton getParty, continueOrder;
         private JLabel party, companyLogo, dinerLabel, entreeOrder;
         private String dinnerEntree[] = {"Filet Mignon", "Chicken Cheese Steak", "Tacos", "Ribs"};
         private JCheckBox mashed, cole, baked, french;
    public Menu1()
         super("O'Brien Caterer - Where we make good Eats!");
         addWindowListener(new WindowAdapter()
         public void windowClosing(WindowEvent ev)
                   dispose();
                   System.exit(0);
         Container container = getContentPane();
         JPanel northPanel = new JPanel();
         northPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 120,15));
         companyLogo = new JLabel("Welcome to O'Brien's Caterer's");
         northPanel.add(companyLogo);
         party = new JLabel("Enter the Total Number in Party Please");
         partyNumField = new JTextField(5);
         northPanel.add(party);
         northPanel.add(partyNumField);
         getParty = new JButton("GO - Continue with Order");
         northPanel.add(getParty);
         northPanel.setPreferredSize(new Dimension(700,150));
         getParty.addActionListener(new ActionListener()
              public void actionPerformed(ActionEvent actionEvent)
                   partyNum = Integer.parseInt(partyNumField.getText());
                   String ans=JOptionPane.showInputDialog(null, "Total Number is party is: "
                   + partyNum + " is this correct?\n\n" + "Enter 1 to continue\n"
                   + "Enter 2 to cancel\n");
                   if (ans.equals("1"))
                        System.out.println(ans+"=continue"); // handle continue
                   else { // assume to be 2 for cancel
                   System.out.println(ans+"=cancel"); // handle cancel
         }}); // end Listener
         JPanel middlePanel = new JPanel();
         middlePanel.setLayout(new FlowLayout(FlowLayout.CENTER));
         dinerLabel = new JLabel("Please enter Diner's name");
         dinerName = new JTextField(30);
         continueOrder = new JButton("continue");
         middlePanel.add(dinerLabel);
         middlePanel.add(dinerName);
         middlePanel.add(continueOrder);
         entreeOrder = new JLabel("Please choose an entree");
         orderComboBox = new JComboBox(dinnerEntree);
         orderComboBox.setMaximumRowCount(4);
    //orderComboBox.addItemListener(
    // new ItemListener(){
    // public void itemsStateChanged(ItemEvent event)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // add entree order to Person
    // continue ** enable the two sides order
         mashed = new JCheckBox("Mashed Potatoes");
         middlePanel.add(mashed);
         cole = new JCheckBox("Cole Slaw");
         middlePanel.add(cole);
         baked = new JCheckBox("Baked Beans");
         middlePanel.add(baked);
         french = new JCheckBox("FrenchFries");
         middlePanel.add(french);
    // CheckBoxHandler handler = new CheckBoxHandler();
    // mashed.addItemListener(handler);
    // cole.addItemListener(handler);
    // baked.addItemListener(handler);
    // french.addItemListener(handler);
         middlePanel.add(entreeOrder);
         middlePanel.add(orderComboBox);
    //container.add(northPanel);
    //container.add(middlePanel);
         container.add(northPanel, java.awt.BorderLayout.NORTH);
         container.add(middlePanel, java.awt.BorderLayout.CENTER);
         middlePanel.setEnabled(true);
         setSize(600, 500);
         show();
    // private class to handle event of choosing Check BOx Item
    // private class CheckBoxHandler implements ItemListener{
    // private int count = 0;
    // public void itemStateChanged(ItemEvent event){
    // if (event.getsource() == mashed)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    // add mashed choice to person's order
    // if (event.getsource() == cole)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add cole slaw to person's order
    // if (event.getsource() == baked)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add baked beans to person's order
    // if (event.getsource() == french)
    // if (event.getStateChange() == ItemEvent.SELECTED)
    // count++;
    //add french to person's order
    public static void main(String args[])
         new Menu1();
    }

  • Two jpanels, after disableing button s-times it appears on the top jpanel

    I create two JPanels. The first JPanel contains JButton, the second JPanl contains overrided paintComponent - it's a simple background.
    Firstly I add 1st jpanel to jframe, then I add the second jpanel with a background image. Then I disable a button and sometime this button appears on top of the second jpanel.
    Resources:
    background.png - 1280x1024x24
    b_h & b_n .png - 122x120x24
    I think that when I make a thread where then I will disable a button, it will appear on top of the second jpanel.
    package swing.test.bug;
    import java.awt.image.BufferedImage;
    import java.io.File;
    import java.io.IOException;
    import javax.swing.JFrame;
    public class MainFrame extends JFrame
      public static int SCREEN_WIDTH = 1280;
      public static int SCREEN_HEIGHT = 1024;
      ScreenWithButton jp1;
      ScreenWithImage jp2;
      public static void main(String[] args) throws IOException
        MainFrame terminal = new MainFrame();
      public MainFrame()
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setUndecorated(true);
        setResizable(false);
        setBounds(0, 0, 1280, 1024);
        getContentPane().setLayout(null);
        (jp2 = new ScreenWithImage()).setBounds(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        getContentPane().add(jp2);
        (jp1 = new ScreenWithButton()).setBounds(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        getContentPane().add(jp1);
        jp1.setVisible(true);
        jp2.setVisible(true);
        setVisible(true);
        jp1.info.setEnabled(false);
      public static final BufferedImage getBufferedImage(String url)
        try
            BufferedImage image = javax.imageio.ImageIO.read(new File("c:\\" + url));
            return image;
        catch (Exception ex)
            ex.printStackTrace();
            return null;
    package swing.test.bug;
    import javax.swing.ImageIcon;
    import javax.swing.JButton;
    import javax.swing.JPanel;
    public class ScreenWithButton extends JPanel
      JButton info;
      public ScreenWithButton()
        setOpaque(false);
        setLayout(null);
        info = new JButton("", new ImageIcon(MainFrame.getBufferedImage("/com/b_n.png")));
        info.setPressedIcon(new ImageIcon(MainFrame.getBufferedImage("/com/b_h.png")));
        info.setDisabledIcon(new ImageIcon(MainFrame.getBufferedImage("/com/b_h.png")));
        info.setContentAreaFilled(true);
        info.setBorderPainted(false);
        info.setFocusPainted(false);
        info.setBounds(1000, 82, 122, 120);
        info.setFocusable(false);
        info.setRolloverEnabled(false);
        add(info);
    package swing.test.bug;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import javax.swing.JComponent;
    import javax.swing.JPanel;
    public class ScreenWithImage extends JPanel
      public ScreenWithImage()
        setOpaque(false);
        setLayout(null);
        ImagePanel p = new ImagePanel();
        p.setImage((BufferedImage) MainFrame.getBufferedImage("/com/background.png"));
        p.setBounds(0, 0, MainFrame.SCREEN_WIDTH, MainFrame.SCREEN_HEIGHT);
        p.setPreferredSize(new Dimension(MainFrame.SCREEN_WIDTH, MainFrame.SCREEN_HEIGHT));
        add(p);
      public class ImagePanel extends JComponent
        private BufferedImage image;
        public void paintComponent(Graphics g)
            if(image != null)
                g.drawImage(image,0,0,null);
        public void setImage(BufferedImage value)
            image = value;
    }

    Hi Alcrouchy,
    I apologize, I'm a bit unclear on exactly what you are describing. If the screen appears to be sliding downward (leaving a blank portion at the top), you may be seeing the Reachability feature of iOS 8 on the iPhone 6/6 Plus. It is intended to make it easier to reach elements towards the top of the screen on the larger iPhones, and is activated by a double tap (not press) on the Home button. There is a bit more about it on this Design page about the iPhone 6:
    Apple - iPhone 6 - Design
    Regards,
    - Brenden

  • Overlapping two operations

    Dear All,
    Up on making settings in customizing for reduction…
    Can we overlap two operations that are in separate Routing? (For those Operations, which are in sequence but existing in separate routing)
    Pavan

    Hi,
    Only in collective order scenario the operation of two routings can be overlapped.
    i.e. In the last operation of the subordinate material routing, overlapping indicator is to be used.
    This is possible from Release 4.5A onwards.Please refer the below link,
    http://help.sap.com/saphelp_46c/helpdata/en/11/1a5313c48e11d1b5df0000e8359890/frameset.htm
    Regards,
    Senthilkumar

  • Is it Possible to Overlap Two or More Video Clips at Once?

    I'm wondering if it's possible to overlap two video clips onto each other (e.g. one video of someone singing and another one of someone playing guitar). This would be similar to overlapping tracks in Garageband. Is it also possible to record over a track (e.g. record a video of someone singing as the video of someone playing guitar is being played?) If so, I was wondering how this can be achieved. Thanks!
    Message was edited by: thedude15

    iMovie Help will lead you to these (and more topics that may be of interest):
      http://docs.info.apple.com/article.html?path=iMovie/8.0/en/23568.html
      http://docs.info.apple.com/article.html?path=iMovie/8.0/en/24545.html
    G5 DP 1.8GHz w/Mac OS X (10.5.6) PowerBook 1.67GHz (10.4.11)   iBookSE 366MHz (10.3.9)  External iSight

  • Two JPanels inside another panel should be equal in width

    Hi everybody,
    I have two JPanels which both have a titledborder. I want them to have the same with, but I can not get it done. You can see how it looks here: http://jborsje.nl/jpanels.png. As you can see the JPanels are not equal in width. Here is the code I used (please note that p_hopsControl = true).
         * Initialize the sidebar of the graph panel.
         * @param p_hopsControl Indicates whether or not a widget for controlling the
         * hops in the graph should be added to the panel.
        private JPanel getSideBar(boolean p_hopsControl)
            // Create the panel.
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.anchor = GridBagConstraints.FIRST_LINE_START;
            // Add the label and the spinner to the panel.
            constraints.gridx = 0;
            if (!p_hopsControl) constraints.weighty = 1;
            constraints.gridy = 0;
            panel.add(getLegend(), constraints);
            if (p_hopsControl)
                constraints.gridy = 1;
                constraints.weighty = 1;
                constraints.weightx = 1;
                panel.add(getHopsWidgets(), constraints);
            // Set the background of the panel.
            panel.setBackground(m_display.getBackground());
            return panel;
        private JEditorPane getLegend()
            String content = "<html><body>" +
                    "<table>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_COLOR_CLASS & 0x00ffffff) + "\" width=\"20px\"></td><td>OWL class</td></tr>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_COLOR_INDIVIDUAL & 0x00ffffff) + "\"></td><td>OWL individual</td></tr>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_COLOR_SELECTED & 0x00ffffff) + "\"></td><td>Node selected</td></tr>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_COLOR_HIGHLIGHTED & 0x00ffffff) + "\"></td><td>Node highlighted</td></tr>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_COLOR_SEARCH & 0x00ffffff) + "\"></td><td>Node in search result set</td></tr>" +
                    "<tr><td bgcolor=\"" + Integer.toHexString(Constants.NODE_DEFAULT_COLOR & 0x00ffffff) + "\"></td><td>Node in search result set</td></tr>" +
                    "</body></html>";
            JEditorPane legend = new JEditorPane("text/html", content);
            legend.setEditable(false);
            legend.setBorder(new TitledBorder("Legend"));
            JPanel panel = new JPanel();
            panel.setBorder(new TitledBorder("Legend"));
            panel.add(legend);
            return legend;
         * Create a panel containing a JSpinner which can be used to set the number
         * of hops, used in the graph distance filter.
         * @return A JPanel containing the hops widgets.
        private JPanel getHopsWidgets()
            // Get the GraphDistanceFilter.
            GraphDistanceFilter filter = m_display.getDistanceFilter();
            // Create the panel.
            JPanel panel = new JPanel(new GridBagLayout());
            GridBagConstraints constraints = new GridBagConstraints();
            constraints.anchor = GridBagConstraints.FIRST_LINE_START;
            // Create the label.
            JLabel label = new JLabel("Number of hops: ");
            // Create the spinner and its model.
            SpinnerNumberModel model = new SpinnerNumberModel(filter.getDistance(), 0, null, 1);
            m_spinner = new JSpinner();
            m_spinner.addChangeListener(this);
            m_spinner.setModel(model);
            // Add the label and the spinner to the panel.
            constraints.gridx = 0;
            constraints.gridy = 0;
            panel.add(label, constraints);
            constraints.gridx = 1;
            constraints.weighty = 1;
            panel.add(m_spinner, constraints);
            // Set the background of the panel.
            panel.setBackground(m_display.getBackground());
            // Add a titled border to the panel.
            panel.setBorder(new TitledBorder("Hops control"));
            return panel;
        }Does anybody know how this can be done?

    Thanks, that solved my issue for the width part. Now the content of the "hops control" panel is centered, althoug I explicitely said "constraints.anchor = GridBagConstraints.FIRST_LINE_START;".
    The update image can still be found here: http://www.jborsje.nl/jpanels.png.

  • Help Please, Problem in displaying same  JTables on two JPanels

    Problem in displaying same JTables on two JPanels. In an application, I have a dynamic display of JTables on one JPanel. After a print preview button action, I have to bring same JTables on another JPanels, while taking this the previous JPanels content(JTables) become invisible? Why this happened? may be single component. Is the Cloning process nedded?

    Hi,
    you can add a component to one container only. If you try to add it to a second container, it will be removed from the first.
    You could try holding one member of the TableModel and set that one to both tables.
    Greets,
    Christian

  • One JPanel is missing after adding two JPanels to a JFrame

    I have two classes, ScoreTableView and CardView, which both extends the JPanel class. ScoreTableView is used to show one table only, and CardView is to show a set of cards for a memory game. My objective is to separate the development of the panels, so that it will easier to modify either of them later. I add instances of these two class to the contentPane of my top level JFrame object. However, I can only see the ScoreTableView(which is supposed to show me a table only) on the top part of the frame, and the CardView panel never show up.
    ScoreTableView.java
      public ScoreTableView(int numberOfPlayer){
    //      Create a model of the data.
            scoreTable = new JTable();//this scoreTable is a JTable object
            scoreTable.setModel(scoreTableData);  //scoreTableData is my data    
            JScrollPane jsp = new JScrollPane(scoreTable);          
            p = this;
            p.setLayout(new BorderLayout());
            p.add(jsp, BorderLayout.CENTER);
        }CardView.java
    public CardView(int w, int h){
            cardWidth = w;
            cardHeight = h;
            JPanel cardPanel = new JPanel();
            cardPanel.setLayout(new GridLayout(cardWidth,cardHeight)); 
            CardImageButton[][] cardsButtons = new CardImageButton[cardWidth][cardHeight];
          // ... more other none GUI coiding 
             }Here's what I have in my main
            Container contentPane = jf.getContentPane();//jf is the JFrame object          
            contentPane.setLayout(new BorderLayout()); 
    //      create the score panel                 
            ScoreTableView scoreTableView = new ScoreTableView(4);
          contentPane.add( scoreTableView, BorderLayout.NORTH);
            //create the cards panel
            CardView cardPanel = new CardView(4,4);
            contentPane.add(cardPanel, BorderLayout.CENTER);
            jf.pack();
            jf.setVisible(true);      

    Sorry, but I copied the wrong files. Now both panels can show up, but the score table is on the NORTH, and the card panel is on the SOUTH(although I set it to CENTER and wish it can occupy the rest of the window), but the center part of the window has nothing. How can I get rid of the white space, so that the score panel can can 30% of the top part of the window(even after resize), and the card panel can occupy the remaining 70%? I can't attach pictures here, otherwise I can upload some screenshot to show you what's the problem I have. Thank you in advance.
    This is my CardView class, I didnt' copy all of them upstair.
    public class CardView extends JPanel{
        private int cardWidth;
        private int cardHeight;
        private CardModel cm;
        private JPanel cardPanel;
        public CardView(int w, int h){
            cardWidth = w;
            cardHeight = h;
            cardPanel = this;
            cardPanel.setLayout(new GridLayout(cardWidth,cardHeight)); 
            CardImageButton[][] cardsButtons = new CardImageButton[cardWidth][cardHeight];
            int[][] list  = init(cardWidth, cardHeight);       
            cm = new CardModel(list);
            int count = 0;
            for(int i=0;i<cardWidth;i++){
                for(int j=0;j<cardWidth;j++){
                    cardsButtons[i][j] = new CardImageButton("Press me"+count, cm, i, j, 0);
                    cardPanel.add(cardsButtons[i][j]);
                    count++;               
    public int[][] init(int n, int m){
            int[][] list  = {
                    {1, 2, 1, 1},
                    {2, 1, 2 , 2},
                    {1, 2, 1, 1},
                    {2, 1, 2 , 2} };
            return list;
        }This is from my main.
           //setup the content panel
            Container contentPane = jf.getContentPane();          
            contentPane.setLayout(new BorderLayout()); 
    //      create the score panel                 
            ScoreTableView scoreTableView = new ScoreTableView(4);
          contentPane.add( scoreTableView, BorderLayout.NORTH);
            //create the cards panel
            CardView cardPanel = new CardView(4,4);
            contentPane.add(cardPanel, BorderLayout.CENTER);
            jf.pack();
            jf.setVisible(true);   ScoreTableView.java
      public ScoreTableView(int numberOfPlayer){
    //      Create a model of the data.
    scoreTable = new JTable();//this scoreTable is a JTable object       
    scoreTable.setModel(scoreTableData);  //scoreTableData is my data            
    JScrollPane jsp = new JScrollPane(scoreTable);                  
    p = this;       
    p.setLayout(new BorderLayout());       
    p.add(jsp, BorderLayout.CENTER);   
    }

  • How can I overlap two clips in final cut

      I am shooting a music video and I want the actor to appear in two spots in the same shot. I shot some test footage today and I set the camera in one spot for both shots. Shot 1 I told him to stand on the right side of the frame for awhile, cut it and then took another shot with him on the left side of the frame. How can I now overlap the two clips in final cut so that i see him on both the right and left sides of the frame at the same time. Thank you so much in advance!!!!

    I apologize if I didn't originally understand your question.  It sounded like you had recorded two scenes with the same camera set in the same place for each scene; one scene with the talent on the left and the other scene with the talent on the right.  And now you wanted to show both shots at the same time so that the talent will be seen on both sides of the screen.  To do that, follow my original instructions above.
    But if I did misunderstand, please rephrase what it is you're trying to do.
    Thanks,
    -DH

  • Overlapping two tables in adobe form

    Hi
    I have a requirement to print details based on different bill numbers in different pages. 
    I have two internal tables 
                    1. it_inrt  containing two fields 
                    2. it_prts containing four fields  .
    Tthese two tables are looping separately. during program execution it_inrt overlaps it_prts. my question is that how to prevent this overlapping i want to print it_prts only after printing all rows of it_inrt and the excess rows will continue in  the next page.
    Please help me to solve this problem.

    Hi,
    You have to 2 internal tables right,
    You have to print the data which is in First internal table and same for second internal table..
    Place thes to tables(one after another ) in Desgin page of - Adobe forms..
    Under page there is  Untitled content area and renamed as ( page area 1)
    In hierachy tab -  By default you will see the Untiled Subform page ( Here drag the First Internal table to here and change the   subflow as flowed ,pagiantaion as continued in untitled area). add another internal table to this form..
    create a new page with only Untitled content area and renamed as ( page area 2)
    Steps:
    Select Untitiled subform - under pagination - Place Select ( In content area of page area 1 )
                                              if dataset must be paginated -  overflow to ( Go to content area of Page area 2 )
                                            - under subform - make the content as flowed and check the allow page breaks within content.
    Regards,
    PraVeen
    Edited by: praveenreddys on Feb 21, 2012 3:53 PM

  • [GUI programming] How do two JPanels interact?

    Hi, all
    I've been looking if there is a standard/mostly-used way implementing GUI applications. e.g.,
    under a JFrame, there are 2 MyPanel exntending JPanel, one placed on the leftside, the other on the rightside. they both have got a bunch of JButtons, JLabels, JList, etc. this is the view.
    but for the control part, here comes the question: I'd would like PanelA to change background color if a Button on PanelB is pressed. where should I place this part of code that controls what happen. I've considered some possibilites, but not sure which one is the best.
    1. implement it in main() like: if PanelA.Button.isPressed(), then PanelB.setBackground(Green)
    pros: centrailized control
    cons: could lead to long & messy code if there are many Panels needed to control
    2. PanelA as Observer, PanelB Observable
    pros: doable
    cons: not very convenient
    3. PanelA & PanelB both singleton, so they can reference to each other directly
    pros: easy implementing
    cons: less flexibility
    if none of them is the way you do, how do you do it then?
    any help will be appreciated.
    thanks.

    You missed the obvious one, just let the controlling panel have a reference to the color panel. In your frame:
    ColoredPanel coloredPanel = new ColoredPanel();
    ControlPanel control = new ControlPanel(coloredPanel);
    // add to conten pane, etcThough ultimately your option two is the best one.

  • MouseListener in two JPanels

    Hi,
    I use a object GoupingPane extends JPanel.
    On this JPanel I add 400 smaller JPanels, like a grid, using FlowLayout. So the groupingPanel is totaly covered.
    The GroupingPanel and the 400 small JPanels have their own MouseListeners.
    The GroupingPanel also got a MouseMotionListener.
    But only the MouseListener of a small JPanel react, and different MouseEvents are defined....
    please help

    Here u have two layers.... the bottom is the groupingPanel and the top layer is formed by all the small panels. So when u click on this the mouseevent for the small panels is fired that being the top layer.
    This is just like having a button on the panel... when you click the button the event for that button is only fired.
    Hope i am clear.

  • How to not overlap two audio tracks?

    Hi, I use Adobe Premiere and I recently I had a problem with Action! (a video recording program) if you register the microphone and the stereo, Premiere overlaps the two audio and is not making me hear my microphone. I also tried to click the check mark on recording program (split audio tracks) but Premiere not divides. How can I create two audio tracks divided on the same record?

    Are you saying that if you walk up to your Mac, iTunes suddenly opens? 
    At any rate, you should be using two different accounts on the Mac, each of you logging into your respective accounts, if you don't want common syncing.

  • How to drag and drop an Image between two JPanels inside a Split Pane

    I'm tring to do that, and my actual problem is as follows:
    I drag the Image from the bottomPanel but I can't drop it in the topPanel, I'm using this classes:
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    import java.awt.image.*;
    public class MoveableComponentsContainer extends JSplitPane {     
         public DragSource dragSource;
         public DropTarget dropTarget;
    public JPanel topPanel = new JPanel();
    public JPanel bottomPanel = new JPanel();
         public int ancho;
    public int alto;
    public MoveableLabel lab1,lab2,lab3,lab4;
    public Icon ico1, ico2,ico3,ico4;
    private static BufferedImage buffImage = null; //buff image
         private static Point cursorPoint = new Point();
    public int getMaximumDividerLocation() {
    return ( ( int ) ( alto * .85 ) );
    public int getMinimumDividerLocation() {
    return( ( int ) ( alto * .85 ) );
         public MoveableComponentsContainer(int Weight, int Height ) {
    alto = Height;
    ancho = Weight;
    setOrientation( VERTICAL_SPLIT);
    setDividerSize(2);
    getMaximumDividerLocation();
    getMinimumDividerLocation();
    setPreferredSize(new Dimension( (int) ( Weight * .99 ), (int) ( Height * .94 ) ) );
    setDividerLocation( getMaximumDividerLocation() );
    System.out.println( " getDividerLocation() = " + getDividerLocation() );
    topPanel.setName("topPanel");
    bottomPanel.setName("bottomPanel");
    bottomPanel.setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    bottomPanel.setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .15 ) ) );
    topPanel. setPreferredSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMaximumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    topPanel. setMinimumSize( new Dimension( (int) ( Weight * .99 ), (int) ( ( Height * .94 ) * .85 ) ) );
    bottomPanel.setEnabled(true);
    bottomPanel.setVisible(true);
    bottomPanel.setBackground( new Color( 57,76,123 ) );
    topPanel. setEnabled(true);
    topPanel. setVisible(true);
    topPanel. setBackground( new Color( 57,76,123 ) );
    setBottomComponent( bottomPanel );
    setTopComponent( topPanel );
    setOneTouchExpandable( false );
    bottomPanel.setBorder(BorderFactory.createTitledBorder("Drag and Drop Test"));
              setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED, Color.white, Color.gray));
    bottomPanel.setLayout( new FlowLayout() );
    topPanel.setLayout(new FlowLayout());
              addMoveableComponents();
         private void addMoveableComponents() {
    ico1 = new ImageIcon( "/usr/local/installers/java/lll/DnD/switchm.gif");
    lab1 = new MoveableLabel("Centrales", ico1, topPanel );
    lab1.setName("labelOne");
    bottomPanel.add( lab1 );
              lab2 = new MoveableLabel("Destinos", ico1, topPanel);
    lab2.setName("labelTwo");
              bottomPanel.add( lab2 );
              lab3 = new MoveableLabel("Registros", ico1, topPanel );
    lab3.setName("labelThree");
              bottomPanel.add( lab3 );
              lab4 = new MoveableLabel("Parametros", ico1, topPanel);
    lab4.setName("labelFour");
              bottomPanel.add( lab4 );
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    import java.awt.dnd.*;
    import java.awt.datatransfer.*;
    public class MoveableLabel extends JLabel implements Transferable {
    final static int FILE = 0;
    final static int STRING = 1;
    final static int IMAGE = 2;
    DataFlavor flavors[] = { DataFlavor.javaFileListFlavor,
    DataFlavor.stringFlavor,
    DataFlavor.imageFlavor };
    public JPanel PanelDestino;
    public JPanel PanelOrigen;
    public DropTarget dropTarget;
    public DropTargetListener dropTargetLis;
         private static final Border border = BorderFactory.createLineBorder(Color.black, 1);
         public MoveableLabel(String text, Icon ic, JPanel DestPanel) {
              super( text, ic, TRAILING);
    PanelDestino = DestPanel;
              MouseEventForwarder forwarder = new MouseEventForwarder();
              addMouseListener(forwarder);
              addMouseMotionListener(forwarder);
              setBorder(border);
              setBounds(0,0,50,100);
              setOpaque(true);
    setTransferHandler(new TransferHandler("text"));
    setBackground( new Color( 57,76,123 ) );
    public synchronized DataFlavor[] getTransferDataFlavors() {
         return flavors;
    public boolean isDataFlavorSupported(DataFlavor flavor) {
    boolean b = false;
    b |= flavor.equals(flavors[ FILE ]);
    b |= flavor.equals(flavors[STRING]);
    b |= flavor.equals(flavors[ IMAGE]);
    return (b);
    public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, java.io.IOException {
    return this;
         final class MouseEventForwarder extends MouseInputAdapter {
              public void mousePressed(MouseEvent e) {
                   Container parent = getParent();
    Container brother = (Container)PanelDestino;
    System.out.println( "Parent 1 = " + parent.getName() );
    System.out.println( "Destino 1 = " + brother.getName() );
    JComponent c = (JComponent) e.getSource();
    System.out.println( "getsource() = " + c.getName() );
    TransferHandler th = c.getTransferHandler();
    th.exportAsDrag( c, e, TransferHandler.COPY_OR_MOVE );
    dropTarget = getDropTarget();
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( false );
    brother.setDropTarget( dropTarget );
    System.out.println( "dropTarget.getComponent().getName() = " + dropTarget.getComponent().getName() );
              public void mouseReleased(MouseEvent e) {
                   Container parent = getParent();
    Container brother = PanelDestino;
    System.out.println( "Parent 2 = " + parent.getName() );
    System.out.println( "Destino 2 = " + PanelDestino.getName() );
    parent.setEnabled( true );
    brother.setEnabled( false );
    for ( int a=0; a < parent.getComponentCount(); a++ ) {
    parent.getComponent( a ).setEnabled( true );
    import java.awt.*;
    import javax.swing.*;
    public class TestDragComponent extends JFrame {
         public TestDragComponent() {
    super("TestDragComponent");
    Toolkit tk = Toolkit.getDefaultToolkit();
    Dimension dm = new Dimension();
    dm = tk.getScreenSize();
    System.out.println(dm.height);
    System.out.println(dm.width );
    Container cntn = getContentPane();
    cntn.setFont(new Font("Helvetica", Font.PLAIN, 14));
    cntn.add(new MoveableComponentsContainer(dm.width,dm.height));
              pack();
              setVisible(true);
         public static void main(String[] args) {
              new TestDragComponent();

    Ok I found the answer to your problem. If you download the tutorial they have the code there it's in one folder. I hope this helps.
    http://java.sun.com/docs/books/tutorial/

Maybe you are looking for