Simple question I think, add JPanel to JScrollPane

I would imagine that for anyone with experience with Java this will be a simple problem. Why can't I add a JPanel to a JScrollPane using myScrollPane.Add(myPanel); ?? it seems to get hidden...
This works correctly:
     //Create a panel
     JPanel panel = new JPanel(new FlowLayout());
     //Make it pink
     panel.setBackground(Color.pink);
     //Make it 400,400
     panel.setPreferredSize(new Dimension(400,400));
     //Create a Scrollpane
     JScrollPane scrollPane = new JScrollPane(panel);
     //Make it 300,300
     scrollPane.setPreferredSize(new Dimension(300,300));
     //Create a JFrame
     JFrame frame = new JFrame("Test Scrollpane");
     frame.setLayout(new FlowLayout());
     //Set close operation
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //Set its size
     frame.setSize(600,600);
     //Add Scrollpane to JFrame
     frame.add(scrollPane);
     //Show it
     frame.setVisible(true);
This doesnt:
     //Create a panel
     JPanel panel = new JPanel(new FlowLayout());
     //Make it pink
     panel.setBackground(Color.pink);
     //Make it 400,400
     panel.setPreferredSize(new Dimension(400,400));
     //Create a Scrollpane
     JScrollPane scrollPane = new JScrollPane();
     scrollPane.add(panel);
     //Make it 300,300
     scrollPane.setPreferredSize(new Dimension(300,300));
     //Create a JFrame
     JFrame frame = new JFrame("Test Scrollpane");
     frame.setLayout(new FlowLayout());
     //Set close operation
     frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
     //Set its size
     frame.setSize(600,600);
     //Add Scrollpane to JFrame
     frame.add(scrollPane);
     //Show it
     frame.setVisible(true);

rcfearn wrote:
I would appreciate it you could read the sample code, I am asking the question as to why I have to do this? For structural reasons I don't want to have to add the JPanel during instatiation of the JScrollPane...Please read the [jscrollpane api.|http://java.sun.com/javase/6/docs/api/javax/swing/JScrollPane.html] To display something in a scroll pane you need to add it not to the scroll pane but to its viewport. If you add the component in the scroll pane's constructor, then it will be automatically added to the viewport. if you don't and add the component later, then you must go out of your way to be sure that it is added to the viewport with:
JScrollPane myScrollPane = new JScrollPane();
myScrollPane.getViewport().add(myComponent);

Similar Messages

  • OAM 10g - Simple question (I think)

    Hey guys, I want to run something by you to see if I'm missing something critical. What I'm trying to do is fairly simple...
    I want 2 login forms for the same webpage, depending on which hostname is used.
    internal.mydomain.com
    external.mydomain.com
    both of these point to an IIS box, which is configured to receive on *:80.. no hostheaders defined.
    Originally, there was only the internal.mydomain.com and that is all setup and working. Accessing http://internal.mydomain.com/secret brings up my "Custom Internal Form".
    I want to add the ability so that when http://external.mydomain.com/secret is acccessed, it brings up my "Custom External Form".
    I have set up a new Host Identifier with external.mydomain.com
    I have copied the policy domain to "My Policy - External" and set it to the new Host Identifier, and specified to use Basic Over LDAP (as a quick test, will create the actual form later)
    When I access external.mydomain.com/secret I keep getting the "Custom Internal Form".
    When I perform an Access Test within oam to the same URL, it shows the correct ("My Policy - External" ) policy domain in the evaluation result, aka.
    This tells me that OAM is configured correctly, but the WebGate isn't reporting properly the host header used.
    Any ideas? I would very much appreciate any insight or suggestions.
    Thanks very much

    Hi Alex,
    Couple of things:
    1. Please check if there is any proxy configured in external.domain.com to route requests to internal.domain.com
    2. Is Login page residing in same webserver as protected page? If so, it will be different for internal and external domains as it will be seperated by a firewall. I would configure a single authentication scheme without specifying anything in challenge redirect field so that Login page will be thrown from the webserver where it is called for secured page.
    3. Please check whether you are able to access login pages of both external and internal domains directly and check for any errors in webserver logs.
    Please post the results.
    Hope this helps!
    -Mahendra

  • A relatively simple question ( I think)

    I'm pretty new to java. I've read a few books and been practicing the basics, and now I'm attempting to learn a bit more through the creation of a simple game. I've been able to get a lot of the groundwork down, however, I'm having trouble figuring out just how to do one of the simple things that I need.
    This game is grid based, and each time a sprite moves it moves a uniform distance of one tile (around 20 pixels). I need to set it up, however, so that the characters don't just "pop" to each location, but that they actually use their walk animation to travel one square's worth of distance.
    I'll post the simple code I tried, along with my thoughts on why it doesn't work, and then I'd like to know if I'm just going about it all wrong, and I should try another method, or there is an error in my code. My comments in the code explain what's going on (or supossed to be).
    public void moveLeft() { //this method is called when the left arrow is pressed
        moving(); //this is a method that simply sets the sprite's animation to a walk loop and changes a couple status variables
        int x = getXPosn(); //get the current x position
        int y = getYPosn(); //get the current y position
        int newx = x - 20; //newx is where I want the sprite to end up
        for (int n = x; n > newx; n--) { 
            setPosition(n, y);
        stopLooping(); //stops the looping animation
    }Now that seems pretty straightforward to me. I set the sprite to its walking animation. I get the current position, and tell it to go 20 pixels to the left, by decrementing 1 pixel at a time. Then, when it gets there, stop looping the animation.
    However, what I end up with is the same as if the for loop is nonexistant and I just used setPosition() to "warp" the character to the new spot. The animation never takes place, and the sprite doesn't "slide" along the screen like I want. Is this because the for loop just processes so quickly from x to (x-20) that its unnoticable? And if so, how do I slow it down so that I can see this animation?
    Perhaps I'm going about it all the wrong way, and there is a better method for getting at what I want. Any help would be greatly appreciated. For what its worth, I do know the moving() method,looping, stopLooping(), setPosition(), and all of that works. When I set it so that holding down an arrow key moves the sprite, it works fine. The sprite moves around, with the walk animation as long as the key is being pressed. That's just not what I need to do here. I just want it to walk a fixed distance, with its animation, from a key press.

    well, it may have bloated my code a bit, but it works. I believe that once I get more of the game elements in place, I'll be able to simplifiy it, but I'm trying to take my time and get each part working solidly before adding more.
    //I have a method that updates my sprite's x,y position each time through the gameloop by simply doing
    locx += mx
    locy += my
    //where locx, locy is the current location and mx, my is the amount of movement (either positive or negative);
    //Then, I needed 2 methods to get it to stop when I wanted.
    public void stepLeft() {
           int x = getXPosn(); //returns the value of the current x position
           moving();
           setStep(-1,0); //this method sets the movement amount each update- (-1,0) means move left 1 pixel on the x axis each update
           moveLeft((x - 20)); //sends the value of where I want the sprite to end up when I'm finished to the other method I created
    public void moveLeft(int x) {
           while (getXPosn() > x) { //this loop runs while the x location of the sprite is greater than the location I want it to end up at.
               isStill = false; //this is just a boolean identifier
           stopMove(); //A method that just stops the looping animation and resets the movement to (0,0)
    }I tried to get it all in one method, but was having trouble, with using getXPosn() in the same method that I needed to check getXPosn() later. It kept creating infinite loops, because (getXPosn() - 20) would change based on the sprite's movement. So my workaround was to send it to another method for the loop.
    As I said, I think this is a little bloated for what the code will be when I'm finished. I need to turn my background into a grid and I'm going to define each tile at some point. Then, I can go back and alter this code so that it just checks if its going into the boundaries of a new tile, rather than needing to use so many methods.

  • First time computer builder - simple question(I think)

    Im putting together my first computer so far without much problem
    This is hardware I have
    380W Antec Power
    865 neo2 board
    2.8 p4 processor
    2x512 mb corsair memory
    lite on cd-rw
    plextor dvd-rw
    200gb western digital special additon hard drive.
    (which came with ata ultra controller card)
    My question is this:
    How should I set up my two optical drives and the hard drive on my available ide connections. Of course I have the two regular ide ports 1&2 and I have the ide3 next to the serial ata ports. I also have the ata ultra controller card plugged into one of the pci ports which gives me two more ide ports. I ve read through the forum listings and have not came across a simple description of how I should configure my hard drive and optical drives. How should I hook up these drives and what settings should I use (master/slave). Any help would be appreciated If it seems like I'm asking dumb questions it's just because I'm real new at this and want every thing to be perfects. thanks

    IMHO
    I would take out ata controller card. Your MB has enough....
    Primary IDE - master  - your WD harddrive
    Primary or Secondary IDE - slave - you lite on cd-rw
    Secondary IDE - master - plextor dvd-rw
    If you will install XP + service pack 1 your harddrive should be OK.
    PS - Just finish to build  about the same config....
    But I made my dvd-rw - external
    added later AFAIK Your 3rd IDE will not support optical drives.
    It is possible to put bootable harddrive on third IDE, but I it is not very simple
    and have no big advantages

  • A very simple question (I think)

    My school has purchased some mac minis to use in our science lab, and now I want to get some very cheap monitors as we have a limited budget. I have some very basic questions that some experienced users could help me with:
    1. Could I use a TV monitor and connect via the HDMI input?
    2. What are the drawbacks when connecting a VGA monitor via the HDMI or mini connector?
    3. Would spending a bit more and getting a DVI capable monitor connected by the supplied "dongle" be best?
    4. What are the best brands of monitor?
    Many thanks,
    Geoff

    Well...
    1. If the TV has HDMI input, absolutely. Your main concern is the level of compatibility with a 'computer type' HDMI input, to avoid overscan/underscan issues.
    2. You can not connect VGA to HDMI without a device converting the signal from digital to analog, and such would cost much more than its worth. The only way to connect VGA avoiding compatibility issues is via the Mini Displayport with the correct dongle from Apple.
    3. I don't see any special advantage to getting a DVI capable computer monitor, over using an HDTV with HDMI or a computer monitor with HDMI. Basically you just need to find whatever display supports the input best as you need, at the best price.
    I won't really answer 4 because there's a lot of opinion in that.

  • Context help (please help, simple question i think)

    Hi, on my webserver, I have a nested tag that goes:
    <Host name="www.mydomain.com">
    <Alias>domain.com</Alias>
    <Context docBase="/home/domainacct/public_html/jsp" path="/jsp" reloadable="true">
    </Context>
    </Host>
    When I use this setup, JSP works! I can access any http://www.mydomain.com/jsp/*.jsp
    But I don't want JSP files to be loadable only from the /jsp directory, as I would like
    to be able to do:
    <Host name="www.mydomain.com">
    <Alias>domain.com</Alias>
    <Context docBase="/home/domainacct/public_html" path="" reloadable="true">
    </Context>
    </Host>
    so that I can access jsp files like: http://www.mydomain.com/test.jsp
    But when I try that setup it doesn't work.
    Do you guys know how I can do this? Thanks.

    nope u can't do that i far as i know.
    the context docBase should be the actual path to the folder. so if your webapp is in C:\TOOLS\webapps\Development than ur docBase is Development....like the root directory for example.
    the context tag as far as i know cannot be used for what u want 2 do. i don't think u can in Java.

  • A simple question I think

    I shot my movie on a Canon XL-1 which is 29.97 fps. I was turned down by a distributor because he told me 30 fps is a hard sell in today's market.
    I did not tell him the movie was shot 30fps, but he knew.
    If I had put my completed movie through cinema tools and exported a 24 fps movie, would it have made a difference?
    Thank you.

    24 fps imaging looks different from 30 fps. 30 frames/sec will look smoother and more 'real'. Think video news.
    24 fps (the frame rate of film) has a slight jerkiness to it as there is a longer time between each frame. To some, this specific image rhythm says "film".
    Graeme Nattress makes a series of filters that will tweek the gamma as well as do the frame rate conversion from 27.97 NTSC to 24p.
    www.nattress.com - film look.
    Good luck.
    x

  • OLE2 ...simple question I think.

    Hi,
    I am trying to use the OLE2 built in to communicate with an API (not microsoft).
    Here's what I have so far...
    Declare
    application ole2.obj_type;
    args ole2.list_type;
    BEGIN
    application:=ole2.create_obj('faxapi.Application');
    Application.addrecipient 'Name', 'surname', '5551212,,,225')
    End
    It's telling me that 'addrecipient' is an 'invalid reference to variable application'
    What am I missing? AddRecipient is correct according to the API documentation I have. I have the API installed on local machine but I don't see how forms knows where it is. Do I need an entry in the registry or something?
    Thanks for you help.
    Bri.

    Application.addrecipient 'Name', 'surname', '5551212,,,225')
    is not valid PL/SQL which is why the compiler is getting upset.
    Break down what you need to do, in this case call a method AddRecipient on the application object
    so the code will probably look a little like this:
    Declare
      application ole2.obj_type;
      args ole2.list_type;
    BEGIN
      application:=ole2.create_obj('faxapi.Application');
      args := ole2.create_aglist;
      ole2.add_arg(args,'Name');
      ole2.add_arg(args,'Surname');
      ole2.add_arg(args,'5551212,,,225');
      ole2.invoke(application,'addrecipient',args);
    End;

  • Simple Question (i think)

    This is the start of my class file, in my uml diagram it states
    +Order()
    +Order(ex :int, mod:int, min:int, custCD:char)
    what's the point of having two order methods, one blank, and one with variables in it?
    public class Order
       // Private Fields
          private int extreme;
          private int moderate;
          private int minor;
          private char customerCode;
          private int applicableDiscount;
           public Order()
             extreme = 0;
             moderate = 0;
             minor = 0;
             customerCode = 'R';
           public Order(int ex, int mod, int min, char custCd)
          }

    I'd argue that you shouldn't have the no-arg constructor, because it means you're creating objects in an incomplete state, which is a bad thing usually.
    On the other hand, JavaBeans requires a no-arg constructor (if I recall correctly) so maybe that's why it's there.
    But then, sometimes people throw in no-arg constructors all the time because they don't know what they're doing. In the same way, sometimes people create getters and setters for all object attributes because they don't know what they're doing.

  • Very basic user, simple question (i think)

    Hi there,
    Very new to dreamweaver, im making a website at the moment, what i dont understand is i have a set template, which i have used for about 6 pages within the website.  On all the pages it is very zoomed in when i preview it in chrome, apart from one page, this page looks perfect, its in perspective and everything isnt too large like on the others.  Is there a way i can make them all follow this one?
    Nevermind that, sorted that
    How do i set the zoom of the page, so when anyone goes onto the page it appears in the correct zoom, rather than far too zoomed in like it does now

    Newtimething wrote:
    Nevermind that, sorted that
    How do i set the zoom of the page, so when anyone goes onto the page it appears in the correct zoom, rather than far too zoomed in like it does now
    Not a clue what your'e talking about. Is the browser set to zoomed by default? Sometimes it can be set in the last position you use it at so you need to re-set it, that' a possibility

  • Simple question I think ( for the expert users of this group)

    In a tabular layout form, when I insert a record, I want a database item, for example b1.aa ( b1 is the database block) to begin with 1( if there are no records inserted yet) and increases automatically, like a sequence.
    1,2,3, 4 ....
    how can I do this?
    in a when - new item instance trigger maybe?
    where? on the block or on the item?
    and which is the right code?
    Thank you all

    Hi Champion
    place ur code in when- new- record- instance at block level and increment it with the value required.
    Thank you
    Sasi

  • Unicode - Simple Question (I think)

    The following code is dynamically generated and executed.  I don't know what table I'm going to get until run-time when I gen this code.  I keep getting the following run-time error:  UC_OBJECTS_NOT_CONVERTIBLE.  Please propose code that works in a Unicode system.  Note that I need to pass the internal table "G" back through a function module interface so I need to have it reference a DDIC object statically.
    REPORT ZDYN1.
    DATA : BEGIN OF G OCCURS 0,
             DATA(5000),
           END OF G.
    PERFORM GET_DATA TABLES g .
    FORM GET_DATA TABLES PASSED_TAB STRUCTURE g.
      TABLES: VBAK.
      FIELD-SYMBOLS <TTT> TYPE ANY.
      ASSIGN VBAK TO <TTT>.
      select distinct * INTO <TTT>
      FROM VBAK
      WHERE
      VBAK~VBELN EQ '0105045404'.
        PASSED_TAB = <TTT>.
        APPEND PASSED_TAB.
      ENDSELECT.
      LOOP AT PASSED_TAB.
        WRITE:/ PASSED_TAB.
      ENDLOOP.
    ENDFORM.                    "GET_DATA

    you wanted to select records from a table (table name known only at runtime - may be a user input) and pass it to a generic itab? right ? if so check out the code of RFC_READ_TABLE function module
    particulary from
    read data from the database and copy relevant portions into DATA
    Regards
    Raja

  • Disk space-simple question

    This is a simple question, I think: I have an external drive (250GB) and have my iPhoto and iTune libraries over there. If I delete about half of my photos from the main library (on the desktop, G4, running 10.4.10) to free up some space, will I still have all my photos from the original main library on the external drive, and just as important, will I still be able to update the external drive as I add new photos to the main library.
    Sorry, I know this is basic stuff but I want to be sure I can free up some space but not lose any photos in the process.
    Thanks, Mike

    Hi--
    If you delete files on the computer they will still remain on the external hard drive. HOWEVER, if you are using a backup program that updates the external drive to reflect the G4 then it may erase whatever you've deleted on the G4. It depends on how the backup program is set (if you are using one).
    If you are not using a backup program and just dragging the folders over to the external drive manually then you would have to be careful not to replace the folders that you want to keep on the external drive. Say for example you have your "Pictures" folder on the external drive. If you delete a bunch of photos on your G4 and then move the "Pictures" folder from your G4 to the external drive, it will REPLACE the "Pictures" folder on the external drive.
    One way to get around this would be to make a seperate folder on your external drive EACH time you made a backup, and drop your "Pictures" folder into that.
    Does this make sense?

  • How to add Panel in JScrollPane? URGENT!

    I need to add a Panel in JScrollPane
    I have try to add JPanel into JScrollPane, but apparently, the JPanel did not show up at all in the JScrollPane (all i see is the border of JScrollPane)
    Then I switch my JPanel to Panel (awt) and it does appear on the JScrollPane, but scrollbars are not visible even i have set the size of the panel is larger than the JScrollPane. (and i also set the VERTICAL_SCROLLBARS_ALWAYS) I can scroll with my mousewhieel, but the panel can scroll out of place(ie outside of the Jscrollpane)
    Can someone teach me how to add a Panel or JPanel to a JScrollPane Please~ Thanks!!!

    here is an example that illustrate my problem:
    import java.io.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import javax.swing.border.*;
    import javax.swing.filechooser.*;
    public class testing extends JFrame
         public testing()
              Container pane=getContentPane();
              pane.setLayout(null);
              setSize(600,600);
              JPanel backgroundpanel= new JPanel();
              backgroundpanel.setLayout(null);
              backgroundpanel.setSize(500,500);
              backgroundpanel.setLocation(0,0);
              Panel insidepanel = new Panel();
              insidepanel.setLayout(null);
              insidepanel.setSize(300,300);
              insidepanel.setLocation(0,0);
              JLabel something= new JLabel("something");
              JTextField someTF= new JTextField(10);
              something.setSize(100,20);
              something.setLocation (20,20);
              someTF.setSize(100,20);
              someTF.setLocation(50,60);
              insidepanel.add(something);
              insidepanel.add(someTF);
              JScrollPane scrollpane= new JScrollPane(insidepanel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS );
              scrollpane.setSize(200,200);
              scrollpane.setLocation(10,10);
              backgroundpanel.add(scrollpane);
              pane.add(backgroundpanel);
              setVisible(true);
              setDefaultCloseOperation(EXIT_ON_CLOSE);
         public static void main(String args[]) throws FileNotFoundException, IOException
                        testing test=new testing();
    apparently, the panel i add in teh scrollpane is on the top layer instead of inside the scroll... can anyone help?

  • Is it possible to add a JPanel to JScrollPane

    i created a JPanel .
    I gave the layout for this panel to be NULL .
    Then i added 16 JLabels in that JPanel(using setbounds)
    when i try to add it to the container i was not able to see last two labels
    So i tried to create a JscrollPane and i add that JPanel to this JScrollPane
    I cant see any difference and the JScrollPane was not working
    The code is:
    JScrollPane scrollPane = new JScrollPane(p);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollPane,BorderLayout.CENTER);
    I dont know
    1) Is it correct to add a JPanel to JScrollPane
    2)Is it compulsory to use a Layout style while using JScrollPane

    i created a JPanel .
    I gave the layout for this panel to be NULL .
    Then i added 16 JLabels in that JPanel(using
    setbounds)
    when i try to add it to the container i was not able
    to see last two labelswhich container ?
    Have you checked that the size of this container is coherent
    with the one of your JPanel ?
    And even before, can this container let the JPanel take the size needed for the
    16 JLabels ?
    So i tried to create a JscrollPane and i add that
    JPanel to this JScrollPane
    I cant see any difference and the JScrollPane was not
    working
    The code is:
    JScrollPane scrollPane = new JScrollPane(p);
    getContentPane().setLayout(new BorderLayout());
    getContentPane().add(scrollPane,BorderLayout.CENTER);
    I dont know
    1) Is it correct to add a JPanel to JScrollPaneyes
    2)Is it compulsory to use a Layout style while using
    JScrollPaneJScrollPane has it own layout.
    However the component/container you whish to view with the JScrollPane
    can have the Layout you whish.

Maybe you are looking for

  • Macbook won't turn on...just not working.

    My Macbook just stopped working. In the evening it was working, but when I woke up the next morning, it was not working. I tried to turn it on, but it wouldn't turn on. I changed power cords, but it was not the charge. Do you have any ideas what else

  • Performance settings

    Hello, I had a few questions regarding PS performance. **Quick note about usage** I mainly use PS for image stacking.  Usually between 30 -50 photos each around 25MB in size.  After stacking them and blending them I usually flatten and then from ther

  • YouTube uploading?

    Hey guys, my question is how come whenever I tend to upload a video created in iMovie from my iPhone 4s or iPad 2 it gives me a message that it could not be uploaded? I checked my YouTube account & I see that whatever video I tended to upload but it

  • UDF-Sales Forecast Row

    Hi All, I' ve added an user defined field in Sales forecast-rows.  But when I open the Sales forecast window that particular UDF is not displays.  If am add in the Title it is displays. Let me know how to get it display in the rows. Regards, Venkates

  • Reduce H.264 size to a format compatible with youtube?

    I seem to be having the opposite problem, as most post on here. My Sanyo HD1000 records full hd, and i took video of a robot i just finished installing. I need to post it to youtube so that my boss and fellow field service engineers can see it in act