How to place panel into frame

Hi Everybody !! I am new to Swing and am working on a GUI based Elevator Simulation System. I am using Frame on which I am trying to put a Panel. But the panel does not set to the size I want it to even if I use setSize() method. I am posting the code .Could anyone please help me.
Thanks !!
package elevator;
import javax.swing.*;
import java.awt.*;
public class Controller {
    public static void main(String args[])
      Container cpane;
      JFrame frame = new JFrame("ELEVATOR");
      cpane = frame.getContentPane();
      Lift1Panel lp1 = new Lift1Panel();
      frame.setVisible(true);
      frame.setSize(1300,800);
      frame.add(lp1);
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
package elevator;
import javax.swing.*;
import java.awt.*;
public class Lift1Panel extends JPanel {
    public Lift1Panel()
     setSize(200,200);
    public void paintComponent(Graphics g)
     super.paintComponent(g);
     Graphics2D g2d = (Graphics2D)g;
     g2d.setColor(Color.WHITE);
     g2d.drawRect(10,10,100,100);  
}

if you use setPreferredSize, don't forget to call frame.pack();. Also, you must realize that the default layout for the contentPane is the BorderLayout, and the default location for adding to this is the BorderLayout.CENTER position. At this location, setPreferredSize is ignored and the central component is expanded to fill the region. You may wish to use a different layout such as the FlowLayout. Experiment with this.

Similar Messages

  • How to place TOC into a different frame in an HTML document?

    I'm now using MS Word 2010 to update a document that I originally created in MS Word 2003.
    I want to create a TOC in a separate frame positioned to the left of the frame that contains the text of the document.  Using help from Technet I've been able to figure out how to create the frame.  If I try to create the TOC in the left frame
    I receive an error to the affect that there is no text to process.  If I create the TOC in the main document (right frame) it works fine and you can follow the links to the various headings in the document.  Just what you'd want.  However, when
    I cut and paste the TOC into the left frame the links become broken.  They seem to end up pointing to themselves which I have a hard time figuring out why anyone would ever want such a result.
    The good news is that when the document is saved in HTML it is done in a form that creates an HTML Frameset which the browser displays just as intended.  However, the reason for doing this is to have the TOC entries end up being hyperlinks which allow
    navigation to the corresponding references in the document frame.
    The really perplexing part is that this worked just right in Word 2003.  I hope the problem I'm having now is that I forgot precisely how to properly perform the task.  If not this amounts to just another one of many reasons to regret buying an
    Office Upgrade.  It will definitely be time to abandon Word 2010 and return to using Word 2003 for this kind of work.

    I went back to one of my older systems which has Office 2003 installed.  It couldn't be any easier to do than the way Word 2003 works.  I didn't need any special knowledge.  You just select the "Format" menu item.  Then the
    drop down sub menu contains an item called "Table of Contents in Frame".  You select that and wha-la you get a frame added to the left of the document with a TOC.  Then you save the document as html (I use filtered html as I think that
    removes some MS Word unique tags that a browser doesn't recognize).  You basically end up with 3 files with names as follows:
    your-document-name.htm, which is the file with the frameset that is to be launched by a browser
    contents.htm
    body.htm
    I'm not sure what happens when name duplication is encountered.  In my case since the document contains graphic files, Word creates a folder named "body_files" and places all of the graphics there.  The contents frame contains links that
    can be selected in a browser to position to the referenced text.
    Relearning how it works in Word 2003 was helpful to figuring what needed to be done in Word 2010.  It looks like in Word 2010 you need to customize the "Quick Access Toolbar".  Then you need to hunt through all of the available commands
    where you will find one called, marvelously, "Table of Contents in Frame".  Once you get that command on your toolbar it becomes as easy as it was in Word 2003.
    One has to wonder why Microsoft thinks it is a good idea to make features of prior versions of Word that were so easy to both use and learn so mysterious on a newer version of Word.  It is pure HELL trying to use what is supposed to be an improved product. 
    This applies to their whole redesign for which I can see absolutely no merit.  Possibly a new user, one who's never experienced Office, might like it but I can't imagine that there are many of those with a past history of using Office who like it. 
    And then it is REAL HELL for someone like me who is only an occasional user.  Of course one reason I've become an occasional user is that I've completely given up on Microsoft for this very reason and now use LibreOffice for just about everything. 
    Unfortunately this was a case where I'd done something in the past using MS Word which I couldn't figure out how to do with LibreOffice, so I guess I'll have to give Microsoft credit for something.

  • Problem displaying panel into frame

    i have a GUI which uses the following frame, the frame
    displays two panels,i set fallPanel's width and height to
    some values but when i run the program i see just a
    small square inside my
    frame instead of a my
    dimensioned fallPanel, could any java guru help me?
    (i post the code for the frame too)
    thanx
    clo
    public class FallFrame extends JFrame
    private Container contentPane;
    private GridBagLayout layout = new GridBagLayout();
    public FallFrame()
    FallPanel fallPanel = new FallPanel();
    SidePanel sidePanel = new SidePanel();
    contentPane = getContentPane();
    contentPane.setLayout(layout);
    GridBagConstraints constraints = new GridBagConstraints();
    constraints.weightx = 0;
    constraints.weighty = 0;
    add(fallPanel, constraints, 0, 0, 1, 1);
    add(sidePanel, constraints, 1, 0, 1, 1);
    repaint();
    private void add(Component c, GridBagConstraints
    constraints,
    int x, int y, int w, int h)
    constraints.gridx = x;
    constraints.gridy = y;
    constraints.gridwidth = w;
    constraints.gridheight = h;
    contentPane.add(c, constraints);

    If you're only using 2 panels, ditch the use of GridBagLayout. It's not very easy to use, and can be quite tricky if you don't set the parameters the way it expects them. In particular, weightx, and weighty are important parameters, and not setting them or setting them incorrectly can cause your components to collapse when the frame is resized.
    If you just have two panels, use BorderLayout. It's much more simple, and I use it almost all the time. Rarely, is there a need for the complexity of GridBagLayout.
    public class FallFrame extends JFrame {
    public FallFrame() {
    getContentPane().setLayout( new BorderLayout() );
    FallPanel fallPanel = new FallPanel();
    SidePanel sidePanel = new SidePanel();
    getContentPane().add( fallPanel, BorderLayout.WEST );
    getContentPane().add( sidePanel, BorderLayout.CENTER );
    One note of caution. Adding the component into the CENTER of BorderLayout will cause it to get all the resize. If you want fallPanel, and sidePanel to share that you can add sidePanel to the EAST instead of the CENTER, and resize will redistribute more evenly. If you have any trouble with BorderLayout read the APIs.
    charlie

  • How adjust front panel placement of a sub VI in the subpanel

    Ok so I've learnt how to use tabs and how to place Sub VI's in the tabs. Last, I would like to change the position of the front panel of some of these sub VI's
    because they're not positioned to my liking  
    Whats the way to go?
    Thanks!
    Solved!
    Go to Solution.

    by default, a VI loaded into a subpanel will show up with the same FP position as when you last saved it.  That's not often what you want, and it's easy to move the FP around inside the window and forget you're changing it.  But this should be good enough to get going.
    one trick that I use is to load the subvi into the subpanel with the same origin in each.  So both the front panel and the pane that it is in have their own coordinates.  For the pane (which is normally the window boundary, and here is the subpanel boundary) the origin is 0,0 at the upper left corner.  On the front panel, look for a little dot with the grid visible.  That's (0,0) on the FP.
    So what we can do programmatically is to use property nodes to set the pane origin to the front panel origin:
     (LV2009f2)
     ok so the snippet ate my constant but there should be two 0's (I32) in that cluster.  Just create a constant on the Origin property and it'll make it.
    -B 
    -Barrett
    CLD

  • How can I move all my bookmarks from different Firefox profiles into one area to organize them and then place them into the different Firefox profiles?

    How can I move all my bookmarks from different Firefox profiles (would like to move whole bookmark folders at once if possible) into one area to organize them and then place them into the different Firefox profiles? This is all under one window user account, I am using windows 8.1. Even if you have information on how to do it on a different windows, it may still be helpful. Thanks for any input you have.

    Just a note about the difference between these two things:
    * "export" and "import" use an ancient HTML document format that all browsers can understand. When you import bookmarks, Firefox may place them into an Imported Bookmarks folder, or into Unsorted Bookmarks. This does not displace existing bookmarks, and Firefox does not automatically remove duplicates.
    * "backup" and "restore" use a more comprehensive JSON data file, which contains extra information about your bookmarks (such as tags) not contained in the traditional export file. HOWEVER, a restore completely replaces all existing bookmarks, so the restore feature cannot be used to merge in a set of additional bookmarks.
    Related support articles:
    * [[Export Firefox bookmarks to an HTML file to back up or transfer bookmarks]]
    * [[Import Bookmarks from a HTML file]]
    * [[Restore bookmarks from backup or move them to another computer]]
    Some users find the disk-based Windows Favorites folder a convenient way to organize bookmarks. If you do, too, and you do not need to preserve tags on your bookmarks, you could export each profile's bookmarks to HTML and import them all into IE11. Organize them in the Windows Favorites folder, then export from IE11 to HTML and import that file into each Firefox profile. See: [http://windows.microsoft.com/en-us/internet-explorer/add-view-organize-favorites].

  • How do I place pictures into photo stream ?

    How do I place pictures into photo stream? (5s)

    Hi there Chirique,
    It looks like the article below may have the information you are looking for.
    iCloud: My Photo Stream FAQ
    http://support.apple.com/kb/HT4486
    -Griff W. 

  • How to place the xml contents into textframe?(cs2_js)

    after flow the xml into indesign document,i able to get the particular xml element and its contents in a variable.
    i want to know how to get certain range of xml element's contents and how to place that in textframe?
    //for get content
    app.activeDocument.xmlElements.item("header1").contents
    if i place the particular element's contents in xml structure extra tags added at edge
    i want to avoid that duplication also
    thanks in advance
    by
    subha

    Hi,
    Use FM WS_FILE_COPY To FIrst Copy the File to some Location
    and Next Use FM TMP_GUI_DELETE_FILE To Delete the File from Old LOcation.
    Regards
    Bala.M

  • HT201263 how to place your device into recovery mode without home button?

    How to place your device into recovery mode without home button?

    Try these programs:
    RecBoot: Easy Way to Put iPhone into Recovery Mode
    The Firmware Umbrella - TinyUmbrella

  • How can I add links to open xml and csv files stored in another location? Please advice how to place links in my frame maker document?

    Hi,
    I would like to know as to how can I add links to open xml and csv files stored in another location? Please advice how to place links in my frame maker document?
    Kindly advice.
    Thanks
    Priya

    Special > Hypertext > Command "open document" will do its best to open the target document inside FrameMaker, which may not be much help; Special > Hypertext > Command "message …" will use the application you specify. The user guide for 7.0 says this about absolute links, and I don't think anything has changed since:
    For example, to start PaintBrush and open the Ship.pcx file on drive C you would use the command message system pbrush.exe C:/Ship.pcx
    I've not often used a relative link, and not recently: the same source says
    folder levels are separated by a slash / even in Windows and Mac
    [relative links] FrameMaker searches for a relative pathname beginning in the folder that contains the current document
    [absolute links] FrameMaker searches for an absolute pathname beginning at the top of the file system. In Windows, the absolute pathname begins with the drive specifier, a colon and a slash.

  • How to divide the iview into frames?

    Hi Experts,
                  Please tell me how to divide the iview into frames.Kindly provide the   steps.Its urgent.
    Regards,
    Nutan

    Hi Nutan,
    Now its clear!!
    If I understand right. You want an overview page full of links to go to your different pages?
    Or maybe you want a link form each page to go to another page?
    In Portal Navigation through hyperlinks is possible.
    You can either do that using EPCM.doNavigate("ROLES://...") {check for EPCM API of help.spa.com}
    Or you could do that by simple
    <a href="http://www.sdn.sap.com/irj/portal/myql">CLICK</a>
    {check for Quicklinks on help.sap.com}
    Either way you'll have to make a small JSP for that.
    Hope this helped
    If so kindly reward with points
    Prem

  • How can we split video into frames

    in jmf, can we split video into frames, how can we do that?
    thank you very much.

    hi!
    i'm also working on a system that requires the extraction of video frames.
    is this the example you were refering? http://java.sun.com/products/java-media/jmf/2.1.1/solutions/FrameAccess.html
    i tried the code and it always gives me a noProcessorException
    i run it as: java FrameAccess c:\1.mpg
    it says that "cannot find processor for c:\1.mpg"
    is it because it doesn't support mpg files? then what media files can it accept?
    or is it because my syntax for URL (c:\1.mpg) is wrong?

  • How draw image into frame in applet

    How draw image into frame in applet.Please give my simple example code.

    http://search.java.sun.com/search/java/index.jsp?qt=%2Bdraw+%2Bimage+%2Bpanel+%2Bhow&nh=10&qp=&rf=1&since=&country=&language=&charset=&variant=&col=javaforums

  • How to place grouped items into another object with content collector tool?

    Is it possible to paste a group into another object (i.e. frame) by using the Content Collector Tool while linking the content?  Paste Into is either deselected or possibly whatever was last saved to the clipboard ends up inserting. I was able to place grouped, linked content into a frame (and later applied a scrollable frame overlay to it) once or twice but can't seem to repeat. Tried selecting the object being pasted into.. holding shift, holding ctrl, all kinds of options, just very confused now.

    Found a potential work-around (I think....).
    1. Use the Content Collector tool and select grouped objects
    2. Select Content Placer tool, check "Create Link"
    3. Place grouped object into doc/onto page with Content Placer tool
    4. Copy placed grouped objects
    5. Paste into frame that will be scrollable later
    For now it seems like the link still works

  • How do I import individual frames from iMovie into iPhoto?

    How do I import individual frames from iMovie into iPhoto? Or how do I export individual frames from iMovie into iPhoto? My final goal is to have a DVD of individual photos from a video I recently shot. Thanks

    Here is one way to do it, although you will see there could be variations.
    1) Open iMovie
    2) Start a new project - name it Stills for iPhoto (or a name of your choice)
    3) Go to your EVENT. Find the spot with the cursor that you want a photo of. Right-click (or control-click if you don't have a mouse) and select ADD STILL FRAME TO PROJECT.
    4) The photo should be in the Project called Stills for iPhoto.
    5) Right-click (control-click) on the photo and select REVEAL IN FINDER.
    6)When the finder window opens, right-click and select COPY. Go to your Desktop or a folder of your choice and right-click PASTE
    7) Drag the photo from your Desktop to iPhoto

  • How do you place contacts into groups on IPad ?

    How do you place contacts into groups on IPad ?

    You can't create groups in the contacts app on the iPad. See my post in this discussion here for alternatives.
    https://discussions.apple.com/message/22045579#22045579

Maybe you are looking for