Adding a panel on top of another panel

Hi all,
I am using NetBeans and have created a JApplet with a JPanel inside (given the default name of panel), and I want to add another panel on top of that.
I have another class, MyPanel that extends JPanel, and I have put some simple graphics in and tested this with a JFrame. In the JFrame, the myPanel is showing up with its graphics.
I tried to add myPanel to panel, but I cannot see myPanel.MyPanel myPanel = new MyPanel();
panel.add(myPanel);Can somebody please point me in the right direction to get myPanel on top of another panel?
Thanks,
Jeff
Edited by: jeff_cia on Nov 20, 2008 6:54 PM

You would do well to read the section on the [layout managers|http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html] at the Sun tutorial site.

Similar Messages

  • How can I from one panel access elements on another panel ?

    I have a JFrame with 2 panels and a JMenu
    I am struggling to find a way how I can access JMenu from one of my panels ...
    Also how can I access elements on one panel from other panel ? At the moment I am passing a reference from one panel to other in the constructor but it's only one way communication now ... I can't go from second panel to first ...
    I am sure there must be an elegant way to solve this problem.
    Many thanks.
    Sergei

    OK I'll give you more details...
    I have a JFrame with multiple panels...
    Also I have a JMenu on JFrame...
    Now when user clicks a button on one of the panels I need to disable a menu item ... this is issue#1
    issue#2 is:
    how do I get two panels (they are separate classes) talking to each other ??? At the moment when I initialize a panel#2 from my Frame I pass to it reference to panel#1 and in this way panel#2 can talk to panel#1 but panel#1 can't talk to panel#2 ...
    I know there must be an elegant way to solve this problem... and I don't like having 2 classes tightly coupled like this... Can I use some kind of nice OO trick for this ? I was reading about custom listeners but I don't want to go crazy on this as I don't have time... actualy I've got only 1 day to solve this issue so any help will be greatly appreciated.
    Many thanks
    Sergei

  • Position panel in centre of another panel

    This is one of those things that should be straightforward, but just isn't working out that way.
    I have a JPanel called PanelA.
    Prompted by a user action, I just want to add another (smaller) JPanel called PanelB in the centre of PanelA.
    I've tried using a BorderLayout on PanelA, and doing this :
    PanelA.add(PanelB, BorderLayout.CENTER);but this adds PanelB at the top of PanelA.
    Does anyone know how I can just have this smaller panel appear dead-centre in the larger panel?

    if you have licence for Borland JBCL library (VerticalFlowLayout)
    you can use this code here.
    public static final void addToPanel(Container xy, JPanel x, String title) {
        String name = x.getName();
        if (name == title) {
          System.err.print("ERROR PANEL IS ALREADY THERE");
          return;
        clearPanel(x);
        EtchedBorder border1 = new EtchedBorder(EtchedBorder.RAISED, Color.white,
                                                new Color(148, 145, 140));
        TitledBorder titledBorder1;
        titledBorder1 = new TitledBorder(border1, title);
        JPanel pan = new JPanel();
        JPanel pan2 = new JPanel();
        JPanel containerPanel = new JPanel();
        pan2.setLayout(new FlowLayout());
        VerticalFlowLayout vertical = new VerticalFlowLayout();
        vertical.setAlignment(VerticalFlowLayout.MIDDLE);
        pan.setLayout(vertical);
        containerPanel.setBorder(titledBorder1);
        containerPanel.add(xy, BorderLayout.CENTER);
        pan2.add(containerPanel);
        pan.add(pan2);
        x.add(pan, BorderLayout.CENTER);
        x.validate();
        x.repaint();
        // x.setName(title);
        x.updateUI();

  • [SOLVED] Openbox and tint2 - adding another panel/ taskbar...

    Hi, so I'm fairly new and usually don't have any questions to ask because I can always find someone who's asked them before
    However, this time, I don't know if I'm not searching the correct way or something, but I just can't find it - and it's a pretty simple thing.
    I have Openbox and my panel is tint2. All very nice, but I was wondering if I can add another panel (that is - I want two tint2 panels). I'm almost sure that's possible due to the way the theming config is organized but I can't find how :s
    So if someone knows or can direct me to the right thread, I'd appreciate it. Thanks
    Last edited by vandakiara (2011-07-12 11:36:30)

    You need two different config files.  See this thread for hints:
        https://bbs.archlinux.org/viewtopic.php?pid=811107

  • Displaying thumbnail images in another panel when it  mouse clicked

    hi,
    I am using JAI, what i am trying to do is i am decoding the tiff file and creating thumbnail of that images and adding thumbnail images to one panel and enlarged images to another panel using DisplayJAI. Now when i will click i thumbnail images on left panel then that image should be display to another panel on right side. Adding both panel to JSplit panel.
    I have no idia how to do it, i tried to do in different way but not able to do that. I hope anybody can give me the hints about this.
    Thanks

    i am adding thumbnail of all images in left panel and enlarged view of each thumbnail is added in right panel , and what i require that when i click thumbnail in left side it's corresponding enlarged image should be visible, suppose in right panel page no. 1 is visible and when i click thumbnail of 13 page in left panel that should be in viewport of right panel.You should put your right panel inside a JScrollPane and call [scrollRectToVisible() |http://java.sun.com/javase/6/docs/api/javax/swing/JComponent.html#scrollRectToVisible(java.awt.Rectangle)] from your panel. You can put the rectangles corresponding to enlarged images in a hash map with the keys being some unique attribute of your thumbnails in left panel. That will help in getting the rectangle to make visible, real fast. Or, you can just put the rectangles in some array indexed according to the thumbnails in left panel.
    I also want to hide the left panel, i think it's possible by Frame.Yes it is possible, but you said you have both your panels in a split pane, so maybe you can use its setDividerLocation() function to hide your left panel.
    Thanks!

  • Add a panel on another panel

    I am working on a program and need to put one panel into another panel . I have been successful at adding the panel
    however when i do this i cannot set the size of the 2nd panel. The first panel on the frame is just fine
    i have tried adding the panel to the first panels constructor this works the panel shows up but i am unable
    to set the size of the panel which is the problem.
    I tried calling this.setSize in the second panels constructor to solve this problem no luck there
    i have also tried adding the 2nd panel to the frame but this produces the same problem as stated above
    im really stumped any help woul be appreciated
    here is some code i have
    This is the frames class with the first panel added
    public ICUFrame () {
            super("ICU");
            canvas= new ICUPanel();
            add(canvas, BorderLayout.CENTER);
            setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            setSize(1000,1000);
            setVisible(true);
        } this is the panel on the frame
    only the constructor is required here as the rest is just code for drawing etc...
    public class ICUPanel extends JPanel {
        DiaDisplay d ;
        SysDisplay s;
        public ICUPanel(){
            super();
            setBackground(Color.BLACK);
            ICUMonitoring monitor = new ICUMonitoring();
            Thread rep = new Thread(new Repainter());
            d = new DiaDisplay(220,20,40,200);
            s = new SysDisplay(420,220,40,200);
            rep.start();
        }// end of constructor
    }this is the 2nd panel i am trying to add to the 1st panel
    public class ECGPanel extends JPanel {
        ecgDisplay e;
         public ECGPanel(){
         super();
         setBackground(Color.white);
         e = new ecgDisplay();
        }// end of constructor
    }

    xiaolixx wrote:
    I am working on a program and need to put one panel into another panel . I have been successful at adding the panel
    however when i do this i cannot set the size of the 2nd panel. The first panel on the frame is just fine
    i have tried.. What happened to your shift key? Please apply it once at the start of every sentence, rather than those rare occasions you 'feel like it'. Adding an upper case letter to each sentence makes it easier for people to quickly scan the text, looking for ways to help. You would not want to make it harder for someone to help, would you?
    ..adding the panel to the first panels constructor this works the panel shows up but i am unable
    to set the size of the panel which is the problem.
    I tried calling this.setSize in the second panels constructor to solve this problem no luck there
    i have also tried adding the 2nd panel to the frame but this produces the same problem as stated above
    im really stumped any help woul be appreciated
    here is some code i haveAlso known as 'uncompilable code snippets'. For better help sooner, post an SSCCE . But first, go through the tutorial to which Darryl linked.

  • Center a panel in another panel

    Good day:
    I am trying to center align (horizontal & vertical centering) a panel in another panel.
    How would I go about doing this?
    I have tried a few different layout managers, but they have not produced the results I am looking for.
    The parent panel is fixed sized, but the child panel is dynamic.
    Please help!!

    Thank you for your post, I greatly appreciate it. However, I tried both of those methods, and my child JPanel is always being placed in the upper left corner of the parent JPanel.
    Here is some code showing my initialization of the JPanel, and the adding of the child JPanel:
    Creating the parent JPanel:
            imagePreview = new JPanel();
            imagePreview.setBackground(Color.white);
            imagePreview.setBorder(new LineBorder(Color.black,1,true));
            getContentPane().add(imagePreview);Adding the child JPanel
    void displayThumbnail()
                  wallpaperChanger.imagePreview.removeAll();
                  wallpaperChanger.imagePreview.add(new viewer(THUMB_LOCATION));
                  wallpaperChanger.imagePreview.repaint();
             }If it helps, the viewer class:
    class viewer extends JPanel
         private Image image;
         public viewer(String fileName)
              Toolkit toolkit = Toolkit.getDefaultToolkit();
              image = toolkit.createImage(fileName);
              MediaTracker mediaTracker = new MediaTracker(this);
              mediaTracker.addImage(image, 0);
              try
                   mediaTracker.waitForID(0);
              catch (InterruptedException ie)
                   System.err.println(ie);
              setSize(image.getWidth(null), image.getHeight(null));
              //show();
         public void paint(Graphics graphics)
              graphics.drawImage(image, 0, 0, null);
    }

  • Valid signature required at bottom. not at top or signature panel.

    Hi Experts,
    I am using Adobe Reader X. When i did validate signature.. green tick mark is coming either top or signature panel side. I required this on exact place of signature. Actually this was working in old versions of adode reader. This feature is not coming on proper place of Adobe reader x. Please provide the solution on this ASAP.
    Thanks
    [email protected]

    Dan:
    The keyword pane used for assigning them to photos cannot be added to the info pane at the window. It's the nature of the beast. You can put in a feature request at http://www.apple.com/feedback/iphoto.html. I've not used it but Keyword Manager might be less obtrusive and work better in the smaller screen of the MBP. You can find it at VersionTracker.com and run it in demo mode.
    TIP: For insurance against the iPhoto database corruption that many users have experienced I recommend making a backup copy of the Library6.iPhoto database file and keep it current. If problems crop up where iPhoto suddenly can't see any photos or thinks there are no photos in the library, replacing the working Library6.iPhoto file with the backup will often get the library back. By keeping it current I mean backup after each import and/or any serious editing or work on books, slideshows, calendars, cards, etc. That insures that if a problem pops up and you do need to replace the database file, you'll retain all those efforts. It doesn't take long to make the backup and it's good insurance.
    I've created an Automator workflow application (requires Tiger), iPhoto dB File Backup, that will copy the selected Library6.iPhoto file from your iPhoto Library folder to the Pictures folder, replacing any previous version of it. It's compatible with iPhoto 08 libraries and Leopard. iPhoto does not have to be closed to run the application, just idle. You can download it at Toad's Cellar. Be sure to read the Read Me pdf file.

  • Child panel in parent panel- strange top value

    Hi!
    I want to write application where I have menu with buttons. Depending on the button pressed the buttons should hide and another design bring on front.
    I don't have any ideas except make that on different panels. I made one parent panel, and a few child panels. When I click button the panel with buttons hides and I'm displaing another panel with width and height equal to parent panel. I can't understand why I have to always have value equal to 30 in top property of child panel. Left property is set o zero and it's displaing OK. When I set 0 to top property the child panel is partially hidden in parent window.
    Why the top property have to be always set to 30 to display exactly panel in panel? I tried to switch on and off titlebar, but it seems taht is no problem. Anyone can explain me that behaviour? Maybe any other ideas to make that kind of application? I don't want to use tabs.

    I'm attaching some pictures so that there's no confusion over what I'm talking about. I'm using the userint/panels.cws, but I modified childPanel1 to be the exact height of the parent panel as you can see in this picture taken from the UI Editor:
    If I don't programmatically set the top of the panel and auto-center vertically is not set to true, then I get this when the panel is loaded. You can see that the panel is being cut off because it loads inside the parent panel using the top value set in the UIEditor.
    If I set the child panel to auto-center vertically it looks like this. You can see that the child panel's title bar is partially obscured due to the auto-centering, and the splitter at the bottom of the child panel is not visible.
    If I then programmatically set the top and left to (0,0) I get this. The frame of the child panel (including the title bar) is hidden, but you can see that everything on the panel is visible:
    If I programmatically set the top to 30 it looks like this. The title bar is visible but you can see that the control at the bottom of the panel is now no longer visible:
    I'm assuming that you're seeing the behavior in the 4th screen shot when you set the top to 0 and something similar to the 5th screen shot when you set the child panel top to 30. I'm guessing that due to the font being used on your machine, the thickness of the child panel title bar is actually 30 so it doesn't stand out quite as much as mine.
    When setting the position of a panel inside another panel, the frame (which includes the titlebar) is ignored, so that (0,0) cooresponds to the very first pixel that is actually visible in the panel. I'm guessing that what you want to do is either:
    A) Disable the titlebar in the child panel and set the frame thickness to 0, or
    B) If you need the titlebar of the child panel to visible, change the height of the of the child panel to be = (height of parent panel - 30).
    Kevin B.
    National Instruments

  • Control tooltip on a panel overlapped by another panel.

    I have asked this question before but I try again.
    Is there any workaround so that the tooltip can be displayed when the location where the tooltip normaly displays is overlapped by another panel ?
    Could I control the position to either left/right instead of below ?
    Solved!
    Go to Solution.

    I'm not sure I completely understand the premise of the question. While it's true that the position of the tooltips cannot be controlled, I'm having a hard time understanding how the tooltips could be overlapped by something else, given that they are floating windows, as Wolfgang pointed out.
    I considered the possibility that you meant "overlapped by another child panel" or "overlapped by another too-level panel". If the tooltip was going to be covered by a child panel, it should definitely display above that panel:
    (In these screenshots, "Text Message" is the control with the tooltip).
    If you meant a top-level panel, then this is a bit trickier to reproduce, since in order for the tooltip to trigger, the panel that holds the control with the tooltip must be the active panel. Therefore, the only way that another top-level panel could overlap that region would be if the other panel was floating. In that case, you have two floating windows. But when I tested it, the tooltip was still on top (I guess because it was created last):
    So, I'm not sure how you were able to cover up a tooltip. Could you maybe post a screenshot, so that I can understand it better?
    Thanks,
    Luis

  • ActionListeners in one panel effecting objects in another

    Hi All,
    I am setting up a gui which contains a JFrame, within which I am adding classes extended from JPanels. These in turn, have more classes derived from JPanels add to then, in the standard Swing way. I want to know the best way of listening for say a button press in one of the base panels, and it causing an effect in another panel?
    I can think of several ways, based around lots of listeners and the messages basically been passed up and across the chain (well tree type structure), but this seems a little cumbersome. If there a way of setting the required available actions without having to do this?
    Adam

    You can use the Mediator Pattern where a 'mediator class handles events.
    The mediator is instantiated in upon the start of the App. then it is passed to all
    classes that need it. Then, those classes that the Mediator needs to have a link to should register
    themselves with the mediator.
    With that said, let's say Class A needs a button actioon to do something to Class B.
    Have a process in Mediator called registerClassB(ClassB classB) so the Mediator has a link to it.
    Then have mediator passed to Class A and Class B. Class A will set it event listeners to the mediator
    (since the mediator will have the proper event listners like mouse and action listners. Class B
    will invoke the mediators registerClassB and pass itself.
    Whatever event you wan to happen, have it set up in the mediator.

  • How to use another panels in status line

    Hi Everyone:
    Can anybody tell me how can i use another panels in the
    Console's status line, I'm using the message line but i need to
    show the user's name and Date-Tiem in another section of the
    status line and not in display controls as i'm already doing it.
    Thanks.

    Do you really need a JSF component for that? You can use h:panelGroup and some JS. But a simple div with some JS is also sufficient.

  • How can transfer data from a dialog to another panel?

    Will anyone help me?Thanks.
    In our project,When the user need to fill some data into the textfield in a panel,he can simplify this action by click a button,when the button is clicked,then a dialog which contains a table of all the imformation of all customers will show,then the user can select one customer's information from the table,after click a button such as "OK",the selected information will show in corresponding textfiled in another panel.Because the dialog and the panel are two
    different object,so how can I transfer the data selected from the dialog to the panel and show the updated information timely??

    try this program. it exchanges some data between s adialog and a frame.
    akz
    * @version 1.20 01 Sep 1998
    * @author Cay Horstmann
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class DataExchangeTest extends JFrame
    implements ActionListener
    {  public DataExchangeTest()
    {  setTitle("DataExchangeTest");
    setSize(300, 300);
    JMenuBar mbar = new JMenuBar();
    setJMenuBar(mbar);
    JMenu fileMenu = new JMenu("File");
    mbar.add(fileMenu);
    connectItem = new JMenuItem("Connect");
    connectItem.addActionListener(this);
    fileMenu.add(connectItem);
    exitItem = new JMenuItem("Exit");
    exitItem.addActionListener(this);
    fileMenu.add(exitItem);
    public void actionPerformed(ActionEvent evt)
    {  Object source = evt.getSource();
    if (source == connectItem)
    {  ConnectInfo transfer= new ConnectInfo("yourname", "pw");
    if (dialog == null)
    dialog = new ConnectDialog(this);
    if (dialog.showDialog(transfer))
    {  String uname = transfer.username;
    String pwd = transfer.password;
    Container contentPane = getContentPane();
    contentPane.add(new JLabel("username=" + uname + ", password=" + pwd),"South");
    validate();
    else if(source == exitItem)
    System.exit(0);
    public static void main(String[] args)
    {  JFrame f = new DataExchangeTest();
    f.show();
    private ConnectDialog dialog = null;
    private JMenuItem connectItem;
    private JMenuItem exitItem;
    class ConnectInfo
    {  public String username;
    public String password;
    public ConnectInfo(String u, String p)
    { username = u; password = p; }
    class ConnectDialog extends JDialog implements ActionListener
    {  public ConnectDialog(JFrame parent)
    {  super(parent, "Connect", true);
    Container contentPane = getContentPane();
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(2, 2));
    p1.add(new JLabel("User name:"));
    p1.add(username = new JTextField(""));
    p1.add(new JLabel("Password:"));
    p1.add(password = new JPasswordField(""));
    contentPane.add("Center", p1);
    Panel p2 = new Panel();
    okButton = addButton(p2, "Ok");
    cancelButton = addButton(p2, "Cancel");
    contentPane.add("South", p2);
    setSize(240, 120);
         //custom method to create and buttons to a container
    JButton addButton(Container c, String name)
    {  JButton button = new JButton(name);
    button.addActionListener(this);
    c.add(button);
    return button;
    public void actionPerformed(ActionEvent evt)
    {  Object source = evt.getSource();
    if(source == okButton)
    {  ok = true;
    setVisible(false);
    else if (source == cancelButton)
    setVisible(false);
    public boolean showDialog(ConnectInfo transfer)
    {  username.setText(transfer.username);
    password.setText(transfer.password);
    ok = false;
    show();
    if (ok)
    {  transfer.username = username.getText();
    transfer.password = password.getText();
    return ok;
    private JTextField username;
    private JTextField password;
    private boolean ok;
    private JButton okButton;
    private JButton cancelButton;

  • My iPhone is split from front panel on top, and back cover of my is swollen too. I am not able to use my phone and I cannot access my data in the phone. Please suggest what could be the cause of this problem?

    My iPhone is split from front panel on top, and back cover of my is swollen too. I am not able to use my phone and I cannot access my data in the phone. Please suggest what could be the cause of this problem?

    It sounds like the battery might have gone bad, and is swelling and causing the symptoms you describe.  Do not attempt to use the phone, but take it to Apple for evaluation.

  • How to send images into another panel

    hi i got two panels
    and one panel creates a couple of images
    and the confusing thing is that i don't want that panel to display my images
    but i want the other side panel to display these images..
    but i don't know how to do it.
    actually i can create two panels in one class and just add them up, but
    my code is quite long and i need to separate these two panels..

    sorry i mean JLabel
    i want to send my JLabel to another panel....

Maybe you are looking for

  • Purchase requisition problem?

    hi what is the difference when deletion indicator is set in purchase requistion line item in the item overview detail and and when we tick on the check box closed in the item detail.As far as my view is concerned both are same(no further purchase ord

  • Outbound Delivery (Tables - VEPO & VEKP)

    Hi All, For a particular outbound delivery i find a few materials which have been packed, But in the table VEPO i do not find an entry for these materials, but i find the entry in VEKP table, can anyone let me know why is there no entry in VEPO table

  • Configuring Main Task of Interactive Activity to use Portlets

    Hi, I currently have a ALBPM implementation where we are using Screenflows in our Main Task of the Interactivity Activity to interact with the user. Now we plan to replace the screenflow with portlets as we are implementing the Weblogic Portal Server

  • Sharing files from windows with mountain lion

    SINCE THE RELEASE OF LION AND MOUNTAIN LION. I HAVE BEEN UNABLE TO PROPERLY SHARE FILES FROM MY MACBOOK PRO (MID 2009) TO MY WINDOWS DESKTOP (VISTA HOME PREMIUM) WITHOUT LOGGING IN AS A GUEST. I PRESS CTRL+K ON MY MAC, I TYPE IN SMB://IP ADDRESS (NOT

  • Find File By Name

    Just upgraded to SL and was disappointed to find the the apple-F dialog box still defaults of find file by content. My gripe is that if you type the word "microsoft" for example, files beginning with this word appear well, and I mean WELL, down the l