Get size of BorderLayout.CENTER

I have a gif that's set to the center of a Panel using BorderLayout.
        pic = new ImageIcon(gifName);
        image = pic.getImage();
        imageWidth = image.getWidth(null);
        imageHeight = image.getHeight(null);
        label = new JLabel(){
                    public void paintComponent(Graphics g){
                        super.paintComponent(g);
                        double width = getWidth();
                        double height = getHeight();
                        Insets insets = getInsets();
                        int hInsets = insets.left + insets.right;
                        int vInsets = insets.top + insets.bottom;
                        // scale up to full image size
                        double wScale = width/(imageWidth + hInsets);
                        double hScale = height/(imageHeight + vInsets);
                        double scale = (wScale > hScale ? wScale < 1 ? wScale : 1 : hScale < 1 ? hScale : 1);
                        g.drawImage(image, 0, 0, (int)(imageWidth * scale), (int)(imageHeight * scale), this);
        };the gif scales dynamically with the size of the frame, the problem is that the gif would be fully visible if it were just added to the contentPane of the frame, but it's added to the CENTER. to the SOUTH i have a 3 x 2 GridLayout of TextFields, and this "covers up" the bottom of the gif. how do i set the gif to only extend to the bottom of the CENTER portion of the panel, instead of the bottom of the frame it is in?

Ok, i got everything displaying now, but i still have the residual problem that when i open an internal frame with a circle in it, and then open an internal frame with a rectangle in it--the circle becomes stretched horizontally. to explain via an example:
-- i open a circle image that is inscribed within a 10 x 10 internal frame. the circle fills up the frame.
-- i then open a rectangle image that is inscribed in a 20 x 10 internal frame. the image of the circle now takes on the width:height ratio of the rectangle. furthermore, when i initially open these images, they are displayed at 1/2 the dimensions of the actual .GIF file, but after opening this second frame, the first one (after i resize a little to update the image) takes on the max size of the most recently opened one (rectangle in this case).
So my circle image is 600 x 600. i open it--it displays as 300 x 300. my rectangle image is 487 x 265. i open it and it displays at ~244 x 133 simultaneously my circle image now looks like an oval. i try to resize it and it jumps to 487 x 265. the reverse occurs if i open the rectangle first, then open the circlei.e. the rectangle assumes the size of the circle, and becomes a square. How do I fix this?
        toolPanel.setSize(new Dimension((int)(imageWidth*.5), (int)(imageHeight*.5)));    
        System.out.println("tool size--w x h: "+toolPanel.getWidth() + " "+toolPanel.getHeight());
        label = new JLabel(){
                    public void paintComponent(Graphics g){
                        super.paintComponent(g);
                        double panelWidth = toolPanel.getWidth();
                        double panelHeight = toolPanel.getHeight() - myPanel.getHeight(); //may need to stick myPanel above this code
                        double labelWidth = label.getWidth();
                        double labelHeight = label.getHeight();
                        System.out.println("pw: "+panelWidth+" ph: "+panelHeight+" lw: "+labelWidth+" lh: "+labelHeight);
                        double wScale = (panelWidth/imageWidth > 1 ? 1 : panelWidth/imageWidth);
                        double vScale = (panelHeight/imageHeight > 1 ? 1 : panelHeight/imageHeight);
                        double scale = (wScale < vScale ? wScale : vScale);
                        int x = (int)(labelWidth - (int)(imageWidth * scale))/2;
                        int y = (int)(labelHeight - (int)(imageHeight * scale))/2;
                        g.drawImage(image, x, y, (int)(imageWidth * scale), (int)(imageHeight * scale), this);                       
        setSize((int)((imageWidth*.5)), (int)(imageHeight*.5));//initial frame size, before any resizing is done              
        ComponentListener l = new ComponentAdapter() {
            double scale = ((imageWidth)/(double)(imageHeight)); //the -90 kind of works with circle
            public void componentResized(ComponentEvent e) {
                Dimension size = getSize();
                Insets insets = getInsets();
                int hInsets = insets.left + insets.right;
                int vInsets = insets.top + insets.bottom;
                // height being resized
                if(size.width/(double)size.height < scale && size.width < imageWidth + hInsets)
                    setSize((int)(size.height * scale), size.height);
                // width being resized
                if(size.width/(double)size.height > scale && size.height < imageHeight + vInsets)
                //if(size.height < imageHeight + vInsets)
                    setSize(size.width, (int)(size.width / scale));
                // max frame size constrained to imageSize
                if(size.width > imageWidth + hInsets || size.height > imageHeight + vInsets)
                    setSize(imageWidth + hInsets, imageHeight + vInsets);
        addComponentListener(l);       
        setOpaque(false);
        //Set the window's location.
        setLocation(xOffset*openFrameCount, yOffset*openFrameCount); //changes location for each new JIF
        //scroll.setViewportView(label);
        toolPanel.add(label, BorderLayout.CENTER);
        toolPanel.add(myPanel, BorderLayout.SOUTH);       
        toolPanel.setOpaque(false); //works
        contentPane.add(toolPanel);

Similar Messages

  • Unable to set JPanel size in BorderLayout.CENTER

    I have a class that defines a GUI for a paint-type program. This class extends JPanel. Within the class, I add a JMenu, a vertical JToolbar to the WEST, a JPanel to the SOUTH and lastly, I add the JPanel that the user draws on in the CENTER.
    From my understanding of the BorderLayout, the CENTER object will take up the remaining available space. The program is run from an applet (which has a setPreferredSize() but it does not seem to affect anything - I think b/c the size specified for the applet in the HTML override it). Anyway, when I set the size of the applet in the HTML, the JPanel in the SOUTH gets cut off. In order to fit it, I have to make the size of the applet bigger - but that makes my CENTER JPanel too big. I need the CENTER JPanel to be a certain size b/c I'm saving the image - which needs to be a certain size.
    I do not understand why the JPanel SOUTH is getting cut off. The JToolBar on the WEST is not that big that it should be governing the size, rather it seems like that JPanel in the CENTER is. I've tried setPreferredSize() and setSize() for that CENTER JPanel, but neither of them seem to help.
    I'll appreciate any thoughts/suggestions - I can elaborate or send code if needed. Thank you all in advance.

    Try using setMinimumSize() and setPreferredSize() for all the other components in the frame other than the CENTER Jpanel. For example, if you want you applet to be 300 pixel high by 500 pixels wide, and you want the centre panel to be 200 x 400 pixels, set the other components as follows:
    Dimension westPanelSize = new Dimension(100, 300)); // width x height
    westPanel.setMinimumSize(westPanelSize);
    westPanel.setPreferredSize(westPanelSize);

    Dimension southPanelSize = new Dimension(500, 100)); // width x height
    southPanel.setMinimumSize(southPanelSize);
    southPanel.setPreferredSize(southPanelSize);Good Luck!
    - David

  • How can I know the size of a JViewport laid out in BorderLayout.CENTER?

    I have a JPanel inside a JScrollPane. The scroll pane is laid out inside of BorderLayout.CENTER. I need to know the size of the JViewport to do stuff like centering and zooming.
    Where can I find the size? All these methods return 0 values for X and Y:
    myScrollPane.getViewport().getSize()
    myScrollPane().getSize()
    myScrollPane.getHorizontalScrollbar().getValue()
    Yes, even the scrollbars won't give me any values! It's all because of the BorderLayout!
    Any ideas? Thanks.

    Sounds like you are accessing the sizes before the views are realized (that is before a call to frame.pack()/show()) They are available only after the layoutManager had a go on it. What is available earlier are preferred/min/max, though.
    Greetings
    Jeanette

  • JPanel not resizing BorderLayout.CENTER component

    I have a JPanel (panel_1) with a BorderLayout. In response to a mous event, I want to replace the component at BorderLayout.CENTER. I'm tracking which component is currently there, so when i get the event, I remove the component currently there, and then add a different one using add(component, BorderLayout.CENTER), and then for good measure I call getLayout().layoutContainer(this) (where "this" is panel_1). At this point, I've got another JPanel, panel_2, in the CENTER position of PANEL_1, and I can see that it's been resized correctly. However, panel_2 also has a BorderLayout, and has a JScrollPane in it's CENTER position. adding panel_2 to panel_1 at center, and redoing the layout, doesn't resize the ScrollPane inside panel_2, even though panel_2 itself is resized.
    Furthermore, in panel_2, I tried overloading setSize(int, int), setSize(Dimension), resize(int, int), resize(Dimension), and even reshape(int, int, int, int), and none of them got called during the layout, but it's size still comes out different on the other side of the layout.
    Can anyone suggest a good way to automatically resize the JScrollPane when the parent container (panel_2) is resized? Is this normal behvior? I thought that BorderLayout was supposed to do this automatically?
    Message was edited by:
    B.Mearns

    LayoutManagers uses the preferredSize to help layout components. The size means nothing, so using setSize() will not help. You should be using setPreferredSize(...).
    You may also want to look at using a [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]Card Layout which is designed to flip back and forth between multiple panels in the same container.
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

  • Dear all, is it normal or common to see the cloudy spot (in various size) at the center of the monitor screen when the iMAC is on longer than an hour or so? Thanks

    Dear all,
    Is it normal or common to see a cloudy spot, in various size, at the center of the monitor screen when the iMAC is on for > 1 hour or so??
    Thx
    T

    Doesn't sound normal to me. If you are under warranty I would get it checked out.

  • I am trying to get into my Game Center app but every time I tap on the app it opens too a blank white screen. I have tried several times to reset my phone but I get the same result.

    I am trying to get into my Game Center app but every time I tap on the app it opens too a blank white screen. I have tried several times to reset my phone but I get the same result.

    Hello there Sweebs44,
    It sounds like you are tapping the Game Center app to open it, but the screen is blank. I recommend signing out of your account:
    Go to Settings > Game Center, where you can:
    Sign out (tap your Apple ID)
    From: iPhone User Guide
              http://help.apple.com/iphone/7/#/iph6c493cac
    Then close all the running apps:
    iOS: Force an app to close
    http://support.apple.com/kb/ht5137
    Double-click the Home button.
    Swipe left or right until you have located the app you wish to close.
    Swipe the app up to close it.
    When you have done that restart the phone sign back into your account and try again:
    iOS: Turning off and on (restarting) and resetting
    http://support.apple.com/kb/ht1430
    Thank you for using Apple Support Communities.
    Take care,
    Sterling

  • How to get my_text in the CENTER aligned on my_form?

    Hello
    I put  a text field (say, its name is 'my_field' 80 characters length) WITH OUT caption and NONE appearence (not Solid box, no Sunken box).
    And i am populating/filling this field with some value PROGRAMATICALLY. Pre-Populating value is vary in its lenght.
    For example in 1st case,  i am pre-populating this my_field with 'AAAAAAAAAAAAA'
    In some other case,  i am pre-populating this my_field with 'AAAA'
    In some other case,  i am pre-populating this my_field with 'AAAAAAAAAAAAAAAAAAAAAAAAAAA'
    Fine.
    But i want print this text/value IN THE CENTER all the time / all cases, no matter How much lenghts's value i am populating, i mean, it shuld come CENTER in the micro soft word
    Pls. let me know how to get this formatting as CENTER ALIGNMENT
    Thank you

    You probably need to set the Align property of the Text field at design time..
    Select the Text Field and then in the Text formatting toolbar, choose the Align Center option to have the text displayed always in the center.
    Thanks
    Srini

  • Someone has been able to get into my Game Center account and has hacked me, I've changed my password and everything but he still finds away to get into my account, he changes my bio and stuff and I don't know what to do, I need desperate help :(

    I've been hacked and I changed my password but he still finds away to get into my Game Center and change my bio. I need serious help

    Have you given your information to anyone?   Family, friend?
    Did you have another device with Game Center on it?   Did you give a new owner of a device any passwords?
    Do you share apple account with a family member?
    Do you have a rescue email set up in your Apple account, with security questions? 
    I suggest you set up a new email account, write everything down and keep it in a safe place.
    New email account and password. Not so easy that it can be hacked.
    In your iTunes account on the computer. Login and change security questions, password and rescue email.
    Again, make sure your password is not easy to guess.   Same with security questions.
    Write it all down and keep it somewhere safe.
    I recommend a password keeper called Enpass.   You can store 10 cards with user names, passwords, notes and account numbers in the free version.
    Then you only have to remember one complicated password to open Enpass and retrieve your information.
    If all else fails, contact apple support.

  • How do I get images to automatically center in a picture box?

    How do I get images to automatically center in a picture box (e.g. place a picture box on a master page and set it so that any image placed inside will automatically center, but not scale)? This was a simple procedure in CS5 (set "Fitting Options" to 'center' by clicking on the center box in the 9-box centering tool) but seems to have disappeared in CS6/CC. Am I missing something?

    Hi and thanks. Actually, my problem is with setting the properties of the image frame to 'align center' before an image is placed, allowing me to place large numbers of images and having them automatically center instead of me centering each one manually. Even when I create an object style the frame will not hold any alignment settings and apply them to the image being placed (unless some manner of scaling has been chosen, which is not something I want). There are work-arounds I have used but it would be nice to be able to just put a picture box on a master page, set it to align it's contents to the center and just be done with it . Thanks though.

  • How do I get the HP solution center back on windows 7

    I have an officjet pro 8500 all in one printer. It was on windows vista but after a computer crash I have installed it on windows 7 but I cannot do anything with it because I am unable to get the hp solution center to work. I have downloaded the new software and drivers and yet it still tells me that the hp soluntion center cannot run because your device installation is not complete. I reran the disc with the network option but it still wont work. Does anyone know of anything I can do to get this to work. I cannot scan or anything with it just copy.
    Thank you

    There are two approaches to try.
    The First Method is easier - the Second Method is more likely to work.
    It would help if I knew your exact printer model; it may not matter.  It sounds like you have already downloaded your printer's installation package from your printer's website -- you will need the installation package for both methods.
    Method One:
    Remove the software bits with the following:
    Fixit -- Fix problems with programs that can't be installed or uninstalled
    Reboot the computer and log in
    Install the software package -- probably from your Downloads folder
    HP Officejet Pro 8500 - A909g - Full Feature Software Win7
    ====================================================================================
    Method Two:
    By pcwizard
    Step one: Clear temp directory
    Type %temp% in the run or search for programs and files field
    Highlight all the files in this folder, and then press the delete key to delete. 
    NOTE:  If you get a message that the file is in use you will need to skip this/these file(s).
    Continue with Step 2 below
    Step two: Downloaded and extract to your system:
    1. Download the Full Feature Software and drivers from your printer's website
    2. Once the download is finished double click on the file to extract the software.
    3. When the installation window opens press the cancel button to stop the installation
    4. Type %temp% in the run or search for programs and files field
    5. Look for, and open the folder starting with 7z (Example: 7zS2356)
    6. Right click on the folder, and select Copy
    7. Close that window, and all your open windows, and then in the middle of the desktop right click your mouse, and select Paste. This will move the 7z folder to your desktop
    8. Open the 7z folder you just copied to your desktop
    9. Open folder Util
    10. Open folder CCC
    11. Run the uninstall_L4
    12. When the uninstall has completed restart the computer
    13. Run Disk cleanup from Accessories\ System Tools folder under all programs
    14. Download and install the latest version of Adobe flash player
    http://www.adobe.com/support/flashplayer/downloads.html
     15. Open the 7z folder, and then double click on the Setup.exe file which will be toward the bottom of the open window. Follow the on screen instructions to reinstall your printer
    ============================================================================
    I hope this helps.
    Kind Regards,
    Dragon-Fur

  • HT204291 I cannot find the AirPlay icon for the life of me. I have iOS 7.0.2 on my iPad Mini. Connected to my WiFi network just fine. I swipe up to get to the control center badges and all I see is the AirDrop icon. Trying to disable mirroring on ipad for

    I cannot find the AirPlay icon for the life of me. I have iOS 7.0.2 on my iPad Mini. Connected to my WiFi network just fine. I swipe up to get to the control center badges and all I see is the AirDrop icon. Trying to disable mirroring on ipad for Netflix streaming and don't know what to do. Any luck out there?

    If you last used an Apple TV to mirror your device and have updated to the newest Apple TV software, go into settings and turn airplay back on. The icon should then appear on your iPad mini when you swipe up allowing you to disable it for Netflix. After updating my Apple TV software for some reason it turned airplay off.
    Bob G

  • How can i get rid of the cents in my account ?

    how can i get rid of the cents in my account ?

    If you want to change countries and can't spend it then you can try contacting iTunes support and ask them if they can remove the balance so that you can do so : http://www.apple.com/support/itunes/contact/- click on Contact iTunes Store Support on the right-hand side of the page, then Purchases, Billing & Redemption

  • How do I get rid of 15 cents on my Apple ID to change countries

    How do I get rid of 15 cents on my Apple ID account to change countries

    Email iTunes Support and ask them to clear your balance.
    http://apple.com/emea/support/itunes/contact.html

  • HOW CAN GET SIZE OF UPLAODED FILES UNDER IRECUIRMENT

    Dear All ,
    How can we get size for Irecuitiment .When users uploaded documents . I want to know the size of uploaded files.
    I try select * from IRC_DOCUEMTNS ..
    Any Idea please.
    Edited by: user12010537 on 21/03/2010 01:29 ص

    Hi Jason!
    I believe that should be all you need to do but a better place to ask would be the Parallels forums. Have a look here <http://forums.parallels.com/>.
    Hope this helps! bill
    1 GHz Powerbook G4   Mac OS X (10.4.8)  

  • How can I get size of fetched data size when run a SQL ?

    Hi,
    When I run a SQL how can I get fetched data size?
    regards,

    We can get it using some calculations:
    1. SQL%ROWCOUNT attribute will fetch you number of rows returned in a SQL statement.
    Problem-->Now you need to get the size of 1 row.
    Solution-->
    Step 1.We can get size of table from dba_segment data dictionary.
    Select block_size from dba_segemnts where segment name like '%YOURTABLE%';
    Step2 . Get count of rows in your table
    Select count(*) from YOUR_TABLE
    Step 3.
    Get size of 1 row--> Divide result in Step1 by result in Step 2.
    Required result--> multiple result in step3 with SQL%ROWCOUNT..
    I hope this is what u want.

Maybe you are looking for

  • Using a variable in two threads...

    i am new to java and have a thread question. i am using a GUI and then run a swingworker thread to get updates from a server on a regular basis. i realize that if the GUI is updated within the swingworker thread i need to use the invokeLater to put i

  • [SOLVED] xf86-intel+xorg-1.5.3 low performance

    Hello, Yesterday i've updated whole arch linux distribution (pacman -Su), unfortunately after update i've discovered that pereformence of glx has fallen significantly. On glxgears i can get max 170 fps, i can't event watch SD movies on mplayer -vo gl

  • Officejet 6500 Wireless Problems

    Like everyone else I would receive on a whim that error message that solution center could not find the printer. So I would delete all the Hp printers under devices and printers and then go to start->hp->-officejet...->add device and go through the p

  • Missing column value when logged on to windows with user id other then admi

    I am using crystal report 10 with oracle 10g database. Application is is developed on vissual studio.net 2005 (vb.net). Reports are launched from vb.net application. My report runs fine when I logon to windows as administrator and launch vb.net appli

  • Home automation - integrate creston with apple

    I implemented home automation with creston system. I'd like to improve the network using time capsule, airport express for new pair of speakers and apple tv to share contents. any experience from somebody?