Can we add same JPanel twice??.. on JFrame and JDialog together!!

Hello Frnds,
my problem is quite weird!! i will try to explain..as much as I can !!
My requirement is I want to show same JPanel in JDialog and JFrame at once..!!
I am adding a
JPanel A ---> JDialog
JPanel A ---> JScrollPanel B
JScrollPane B ---> JFrame.. and making frame and dialog visible together.. but JPanel is visible in dialog only..
if i dont add in JDialog.. then JPanel is visible in frame.. !!.. but why that??
JFrame fr = new JFrame();
JPanel np = new JPanel();      // This JPanel is added Twice
np.setBounds(0, 0, 128, 128);
JScrollPane scroll=new JScrollPane(np);      // Once JPanel added here..
scroll.setPreferredSize(new Dimension(385,385));
fr.add(scroll);
JDialog dlg=new JDialog(fr, "Another Panel", false);
dlg.add(np);                        // Second Time JPanel added here..
dlg.pack();
dlg.setVisible(true);
fr.setVisible(true);

Let's make it very clear : it is NOT possible to add
the same instance of a component to two different
containers.
Is it possible to have frame with component.. but on closing that frame component shifts to another frame.. and vice versa I will add to the above:
it is NOT possible to add the same instance of a component to two different containers... at the same time. Does that clarify it?
Why is it so hard to try it yourself?
Instead of waiting a couple of hours hoping someone answers the question you could have solved your problem in a couple of minutes.

Similar Messages

  • Can not add a picture to the JFrame from an ActionListener class

    As topic says, I can not add a picture to the JFrame from an ActionListener class which is a class inside the JFrame class.
    I have a Map.java class where I load an image with ImageIcon chosen with JFileChooser.
    I my window class (main class), I have following:
    class OpenImage_Listener implements ActionListener
         public void actionPerformed(ActionEvent e)
              int ans = open.showOpenDialog(MainProgram.this);     // "open" is the JFileChooser reference
              if(ans == open.APPROVE_OPTION)
                   File file = open.getSelectedFile();                    
                   MainProgram.this.add(new Map(file.getName()), BorderLayout.CENTER);     // this line does not work - it does not add the choosen picture on the window,
                            //but if I add the picture outside this listener class and inside the MainProgram constructor, the picture apperas, but then I cannot use the JFileChooser.
                            showMessageDialog(MainProgram.this, fil.getName() ,"It works", INFORMATION_MESSAGE);  // this popup works, and thereby the ActionListener also works.
    }So why can�t I add a picture to the window from the above listener class?

    The SSCCE:
    Ok, I think I solved it with the picture, but now I cannot add new components after adding the picture.
    Look at the comment in the actionlistener class:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.io.*;
    public class Test extends JFrame{
         JButton b = new JButton("Open");
         JFileChooser jfc = new JFileChooser(System.getProperty("user.dir"));
         Picture pane;
         Test(){
              super("Main Program");
              setLayout(new BorderLayout());
              JPanel north = new JPanel();
              add(north, BorderLayout.NORTH);
              north.add(b);
              b.addActionListener(new Listener());
              setVisible(true);
              setSize(500,500);
              pane = new Picture("");
              add(pane, BorderLayout.CENTER);
         class Listener implements ActionListener {
              public void actionPerformed(ActionEvent e){
                   int ans = jfc.showOpenDialog(Test.this);
                   if(ans == jfc.APPROVE_OPTION)
                        File file = jfc.getSelectedFile();
                        Test.this.add(new Picture(file.getName()), BorderLayout.CENTER);
                        pane.add(new JButton("NEW BUTTON")); // Why does this button not appear on the window???
                        pane.repaint();
                        pane.revalidate();
         public static void main(String[] args)
              Test t = new Test();
    class Picture extends JPanel
         Image pic;
         String filename;
         Picture(String filename)
              setLayout(null);
              this.filename = filename;
              pic = Toolkit.getDefaultToolkit().getImage(filename);
            protected void paintComponent(Graphics g)
                super.paintComponent(g);
                g.drawImage(pic,0,0,getWidth(),getHeight(),this);
                revalidate();
    }

  • Can I add a JPanel in JScrollPane?

    Can I add a JPanel in JScrollPane?
    If I added,components in the JPanel can effect the JScrollPane?
    thanks!

    Can I add a JPanel in JScrollPane?yes you can - it is meant for this.
    If I added,components in the JPanel can effect the
    JScrollPane?if you mean affect like focusing and scrolling to a certain place - the answer is yes, you have to look the right functions in each component you insert to the panel.

  • I have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    i have two iphone one is iphone 5 and othere is iphone 4 . can i use same id for both ? And do i have to purchase the application again for iphone 4 which i have buyed for iphone 5.??

    You can use the same Apple ID for both phones, you would then be able to use the purchased Apps/Content on both phones without having to pay again.

  • I have made a calendar in iCal on my MacBook Pro, but I cannot seem to find out how I can 'download' that same calendar on my iPhone and iPad. Does anyone know how to do this? Thanks in advance.

    I have made a calendar in iCal on my MacBook Pro, but I cannot seem to find out how I can 'download' that same calendar on my iPhone and iPad. Does anyone know how to do this? Thanks in advance.

    I have made a calendar in iCal on my MacBook Pro, but I cannot seem to find out how I can 'download' that same calendar on my iPhone and iPad. Does anyone know how to do this? Thanks in advance.

  • How can I add a person to an event (and send that person an invite) without resending the meeting invitation to all participants?

    How can I add a person to an event (and send that person an invite) without resending the meeting invitation to all participants?

    Apple doesn't make it easy to do what you want.  However, here's how I do it. 
    Select the photo you want to move and create a new Event for it via the Event ➙ Create Event menu option.
    In the Event mode select the new Event with the one picture and drag it onto the Event you want to move the photo to.

  • Can we use same Business Service for Sender and Receiver

    Can we use same Business Service for Sender and Receiver

    Hi
    In addition to the above infomation explaining about the Business Service..
    Business Service: Address an abstract business entity as the sender or receiver of messages.
    Using a business service, you can define the technical or business subunits of the companies involved and then assign them the relevant interfaces.
    The business services are used when configuring cross-company processes also..
    regards
    Kishore

  • When I try to open a pages document on my mac book pro it says "The file 'thesis.pages' couldn't be opened." But i can open the same file on my iPad and iPhone without a problem.

    When I try to open a pages document on my mac book pro it says "The file 'thesis.pages' couldn't be opened." But i can open the same file on my iPad and iPhone without a problem.

    Thanks very much for the instructions.  I encountered this problem this morning myself and the recommendation fixed the problem immediately.  When things like this happen with iCloud and Pages it makes me wonder if I might be better off using something else, having just recently had to fix the problem that the current Pages can't read documents I created with a much earlier version until they were "upgraded" by an interim version.

  • What is the difference between JFrame and JDialog?

    Is there any difference between JFrame and JDialog except that the JDialog can be modal?
    Is there any reason to use JFrame at all if i can achive the exactly the same with a JDialog?

    API wise they are basically the same, but they are usually built on top of different heavyweight components. Some platforms treat frames quite a bit differently than they do dialogs.

  • How do I add multiple JPanels to a JFrame?

    I've been trying to do my own little side project to just make something for me and my friends. However, I can't get multiple JPanels to display in one JFrame. If I add more than one JPanel, nothing shows up in the frame. I've tried with SpringLayout, FlowLayout, GridBagLayout, and whatever the default layout for JFrames is. Here is the code that's important:
    import java.awt.Container;
    import java.awt.FlowLayout;
    import java.awt.GridBagConstraints;
    import java.awt.GridBagLayout;
    import javax.swing.*;
    public class CharSheetMain {
          * @param args
         public static void main(String[] args) {
              // TODO Auto-generated method stub
              CharSheetFrame frame=new CharSheetFrame();
              abilityPanel aPanel=new abilityPanel();
              descripPanel dPanel=new descripPanel();
              frame.setLayout(new FlowLayout());
              abilityScore st=new abilityScore();
              abilityScore de=new abilityScore();
              abilityScore co=new abilityScore();
              abilityScore in=new abilityScore();
              abilityScore wi=new abilityScore();
              abilityScore ch=new abilityScore();
              frame.add(aPanel);
              frame.add(dPanel);
              frame.validate();
              frame.repaint();
              frame.pack();
              frame.setVisible(true);
    }aPanel and dPanel both extend JPanel. frame extends JFrame. I can get either aPanel or dPanel to show up, but not both at the same time. Can someone tell me what I'm doing wrong?

    In the future, Swing related questions should be posted in the Swing forum.
    You need to read up on [How to Use Layout Managers|http://download.oracle.com/javase/tutorial/uiswing/layout/index.html]. The tutorial has working example of how to use each layout manager.
    By default the content pane of the frame uses a BorderLayout.
    For more help create a [SSCCE (Short, Self Contained, Compilable and Executable, Example Program)|http://sscce.org], that demonstrates the incorrect behaviour.
    The code you posted in NOT a SSCCE, since we don't have access to any of your custom classes. To do simple tests of adding a panel to frame then just create a panel, give it a preferred size and give each panel a different background color so you can see how it works with your choosen layout manager.

  • How can I add the key listener to JFrame

    Hi,
    How can I add the Key Listener to the JFrame? I want to show the Windows default popup which comes after right clicking on the frame's header. I want to add the key board support for the same

    1. Make sure that key events are enabled on your component. (AWTMulticaster.enableEvents(...)
    2. add the keylistener

  • Can't hit same key twice

    This is very strange, but whenever I'm in Vista in Boot Camp on my MacBook, the built-in keyboard will sometimes freak out and stop letting me hit the same key twice in a row.
    As soon as I hit a key once, it dies until I hit another key. I have precisely NO idea why it happens or what's causing it, and it does go away when I restart, it's just very irirtating when I'm in class trying to take notes.
    Anybody have any solutions?

    Download and install the 10.6.8 Update Combo.

  • How can I add file attachment to my form and get the attachment by email?

    I'm using this code and it works fine, but I don't get the attachment file in the email. How can I add this to my code?
    HTML
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>Untitled Document</title>
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <script src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js" type="text/javascript"></script>
    <script type="text/javascript">// <![CDATA[
                  $(document).ready(function() {
                    $("#form1").validate({
                      rules: {
                        first: "required",// simple rule, converted to {required:true}
                        email: {// compound rule
                        required: true,
                        email: true
                      last: {
                        last: true
                      comment: {
                        required: true
                      messages: {
                        comment: "Please enter a comment."
    // ]]></script>
    <script type="text/javascript">// <![CDATA[
    function validate ()
              if (document.form1.first.value == "")
              alert("Please enter your First Name");
              document.form1.first.focus();
              document.form1.first.style.border="1px solid red";
              return false;
              else if (document.form1.last.value == "")
              alert("Please enter your Last Name");
              document.form1.last.focus();
              document.form1.last.style.border="1px solid red";
              return false;
              else if (document.form1.emailaddress.value == "")
              alert("Please enter your Email Address");
              document.form1.emailaddress.focus();
              document.form1.emailaddress.style.border="1px solid red";
              return false;
    function has_focus() {
        if(document.form1.first.value == "")
                                  document.form1.first.focus();
                                  document.form1.style.first.border="1px solid green";
    function set_focus(x)
              document.getElementById(x).style.border="1px solid #80CA75";
    function clear_focus(x)
              document.getElementById(x).style.border="1px solid #DBDFE6";
    // ]]></script>
    </head>
    <body>
    <p><span style="color: #666666; text-align: center; font-size: 13px;">Please complete this form if you have any technical issue.</span></p>
    <form id="form1" action="http://www.southsun.com/php/tech_issue.php" enctype="multipart/form-data" method="post">
    <table style="width: 850px; font-size: 15px; padding-left: 20px; text-align: center;" border="0">
    <tbody>
    <tr>
    <td style="text-align: left; padding-bottom: 20px;" colspan="2">
    <h2><span style="color: #666666;">Please complete this form if you have any technical issue.</span></h2>
    </td>
    </tr>
    <tr style="padding-top: 40px;">
    <td style="text-align: left;"><span style="color: #abaf6f;"><strong>First Name</strong>:*</span><input id="first1" name="first" type="text" />  <br /><br /> <span style="color: #abaf6f;"><strong>Last Name</strong>:*</span><input id="last1" name="last" type="text" /><br /><br /> <span style="color: #abaf6f; padding-right: 33px;"><strong>Email</strong>:</span><span style="color: #abaf6f;">*</span><input id="email1" name="email" type="text" /><br /><br /> <span style="color: #abaf6f;"><strong>Shipping Method:</strong><br /></span> <input name="shippingmethod" type="radio" value="prioritymail" /> Priority Mail                                                                 <input name="shippingmethod" type="radio" value="store" /> In Store Pick up <br /> <input name="shippingmethod" type="radio" value="ground" />  Ground                                                                       <input name="shippingmethod" type="radio" value="3day" /> 3 Day Select<br /><br /> <span style="color: #abaf6f;"><strong>Payment Method:</strong><br /></span> <input name="paymentmethod" type="radio" value="paypal" /> Paypal Method                                                       <input name="paymentmethod" type="radio" value="creditcard" /> Credit Card<br /> <strong><br /> <span style="color: #abaf6f;">If getting an error message, please explain the error:</span></strong><span style="color: #abaf6f;"> <br /></span> <textarea id="errormessage" cols="20" rows="2" name="errormessage"></textarea><br /><br /></td>
    <td style="border-left: 1px solid grey; padding-left: 40px; text-align: left;"><span style="color: #abaf6f;"><strong>If using Paypal, Were you redirected successfully?</strong><br /></span> <input name="paypalredirect" type="radio" value="yes" /> Yes                                                                 <input name="paypalredirect" type="radio" value="no" /> No<br /><br /> <span style="color: #abaf6f;"><strong>If using Credit Card, Did you get an error?</strong><br /></span> <input name="carderror" type="radio" value="yes" /> Yes                                                                  <input name="carderror" type="radio" value="no" /> No<br /><br /> <span style="color: #abaf6f;"><strong>What happened after clicking place order? </strong><br /></span> <textarea id="placeorder1" cols="20" rows="2" name="placeorder"></textarea><br /><br /> <span style="color: #abaf6f;"><strong>Comments</strong>: <br /></span> <textarea id="comments1" cols="20" rows="2" name="strcomments"></textarea><br /><br /> <span style="color: #abaf6f;"><strong>Attach PrintScreen</strong>: <br /></span> <input name="strresume" type="file" />
    <div style="height: 50px;"> </div>
    </td>
    </tr>
    <tr>
    <td style="padding-top: 20px;" colspan="2">( * ) indicates required fields</td>
    </tr>
    <tr>
    <td style="text-align: center; padding-top: 20px;" colspan="2"><input class="button" name="submit" type="submit" value="Submit" />                        <input class="button" name="reset" type="reset" value="Reset" /></td>
    </tr>
    </tbody>
    </table>
    </form>
    </body></html>
    PHP
    <?php
    echo $savestring;
    //--------------------------paramaters--------------------------
    // Subject of email sent to you.
    $subject = 'prueba con uploads';
    // Your email address. This is where the form information will be sent.
    $emailadd = '[email protected]';
    // Where to redirect after form is processed.
    $url = 'http://www.pch-graphicdesign.com';
    // Makes all fields required. If set to '1' no field can not be empty. If set to '0' any or all fields can be empty.
    $req = '0';
    $target_path = "http://www.pch-graphicdesign.com/php/uploads/";
    $target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
    $text = "Results from form:\n\n";
    $space = ' ';
    $line = '
    foreach ($_POST as $key => $value)
    if ($req == '1')
    if ($value == '')
    {echo "$key is empty";die;}
    $j = strlen($key);
    if ($j >= 20)
    {echo "Name of form element $key cannot be longer than 20 characters";die;}
    $j = 20 - $j;
    for ($i = 1; $i <= $j; $i++)
    {$space .= ' ';}
    $value = str_replace('\n', "$line", $value);
    $conc = "{$key}:$space{$value}$line";
    $text .= $conc;
    $space = ' ';
    mail($emailadd, $subject, $text, 'From: '.$emailadd.'');
    echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
    ?>

    Sending a file as an attachment to an email involves setting the correct MIME type and headers. There's a brief tutorial here: http://webcheatsheet.com/php/send_email_text_html_attachment.php.
    Also, you need to use the same name as in your form. In the script you have shown here, the name of the file field is strresume, but your processing script uses this: $_FILES['uploadedfile']['name']. It should be this: $_FILES['strresume']['name']

  • Can I add both a HD 2600 XT and 8800 GT to a new Mac Pro

    I just purchased the new Mac Pro and got the base config. with the HD 2600 XT. The way my setup works is I need to use this Mac Pro with 3 monitors, all within close areas within the office. We will have a wireless/bluetooth keyboard/mouse and since it's within 15 ft. we don't expect to have problems. With the monitors we will have to run DVI Cables around doors so it should be more like 20-22 ft. I was going to purchase a DVI splitter such as the one from Monoprice.com but figured my best solution is to add a video card. These monitors need to be mirrored but won't have to all display at the same time.
    I came to the conclusion it's almost as good to just add a 2nd video card. I am considering the 8800 GT but am wondering, if I have a system with both the 2600 XT and 8800 GT will it cause problems? To be safe am I better off just getting another 2600 XT? If so, where can I purchase it? I can find the 8800 GT on Apple's site but can't find the 2600 XT anywhere. I don't do much gaming other than X-Plane but do some Adobe CS3 work in Photoshop, Illustrator, and inDesign, some HD video in Final Cut Studio, and other than that basic office work in iWork, Office, and mail, ical, and safari web browsing.

    When I called Apple they told me that I wouldn't be able to use my current 2600 with the 8800 (if it ever gets here). They said I could use two 8800's or multiple 2600's but not an 8800 and 2600 together. I may give it a try anyways because I'd like to run 3 monitors.
    If I were you I think I'd just get one of the 2600's that are likely to start showing up on E-bay when people start to finally get their 8800's. That is if you can wait until March.
    Best of luck.

  • How can I use same iTunes on iPad 64GB and iPhone 5 16 GB memory

    How can I use same iTunes account on iPad 64GB and iPhone 5 16 GB memory

    Just connect them your computer. iTunes will treat each device separately. Or if you mean iTunes Store account, you can choose what you download to each device, either directly from the iTunes Store or in synching from iTunes on your computer, as long as you don't have automatic downloads turned on.
    Regards.
    Forum Tip: This forum is for questions about using iPads in companies and organizations. Questions about the general use of iPads will normally best be posted in the Using iPad forum.

Maybe you are looking for

  • How can I separate a clip in an event in iMovie'08?

    how can I separate a clip in an event in iMovie'08?

  • Cannot Open Camera RAW files: Do I need to reinstall PS?

    Hello, I reinstalled PS today after I got my computer back from the repair shop. Now it will not open RAW files. I get the following error message: Any thoughts on what might be going on?  I realize this is an Apple screen shot, but I think this migh

  • Product type 55c rupee term loan tds and withholding tax deducted

    Dear team any one guide me while posting intrest by using t code tbb1 systen calculates tds and withholding tax but i want only tds how can i remove withholding tax .  Pls respond urgently sarath

  • Multi monitor issues with resolution(?)

    At a customer I have got a really strange and annoying problem. The customer has got a Hyper-V VM with 2012 R2 Server as a RDS server aka Terminal Server. One user has got issues with his multi monitor setup. The connection settings seems to be OK. I

  • Format Mask in Session state

    In a Summary Region (Page 6) I have changed one field to text, edited the field with no format mask. In the entry form on the pervious page, the column properties are Database Column, and Always replace value in Session State with the Money format Ma