Why is my panel's preferred size changing as I resize the window?

I have a JEditorPane inside a JPanel, which is wrapped in a JScrollPane. The JEditorPane contains a wide image and I expect to see horizontal scrollbars if the viewport is smaller than the minimum size needed to display the image.
When my panel is displayed for the first time and the viewport size is smaller than the image, the horizontal scrollbars appear and the size of the scrollable area is set to the width of the image. This is the expected behaviour. When I resize the panel so that its is wider than the image and the scrollbars are no longer needed, the scrollbars disappear. However, when I shrink the panel back, the scrollbars appear at the correct "time" (when the edge of the image is reached), but the scrollable area is too wide, similar to the size I had stretched the panel out to.
I am printing out the preferred size that the panel is returning (which will be used to set the scrollable area), and it seems to keep changing. The preferred size seems to grow with the panel's actual size, but it does not shrink back when I make the panel smaller.
Anyone has any idea on what might be happening?

Welcome to the Sun forums.
>
Anyone has any idea on what might be happening?>It probably has to do with the Java code used. Can you prepare an SSCCE that shows the behaviour?

Similar Messages

  • Determine preferred size to be set for the JPanel attached to JScrollBar

    Determine what preferred size to be set for the JPanel attached to JScrollBar.
    Hello all, I am having a JPanel, where new components will be added into it during run-time. When there are too many components inside the JPanel, I need to re-set the JPanel preferred size so that the JScrollBar is scrollable.
    I was wondering what is the good method to determine the preferred size of JPanel during runtime?
    Currently, I am using
    myJPanel.setPreferredSize(new Dimension(
    numberOfNewComponent * preferred width of each component,
    numberOfNewComponent * preferred height of each component
    ));Is there any better alternative?
    Thank you very much.
    yccheok

    Usually a container such as JPanel will calculate its own preferred size from its layout manager - calling setPreferredSize is often unnecessary.
    When you add a component to your JPanel its preferred size will change automatically.
    What's wrong with the behaviour when you simply add your JPanel to a JScrollPane and let it manage its own preferred size?
    Hope this helps.

  • Why does the text size shrink when I make the window smaller?

    I have some notes in a DOCX page.  I don't want the entire page blocking up the desktop yet I want to see the notes.  When I change the size of the page, the text shrinks too.  How useless is that?
    How to I keep the text normal size and have a smaller page?
    Everything I know I learned from my cat. No matter what the situation is, there is a napp for that.

    Hi,
    When we I change the size of the page manually in Word 2013, the text won’t shrinks. I also resize the window via code below:
    Sub ReSizeWinodw()
    Application.ActiveWindow.WindowState = wdWindowStateNormal
    Application.ActiveWindow.Width = 500
    Application.ActiveWindow.Height = 500
    End Sub
    It won’t shrink the text too. If you are using code to resize the window of Word, would you mind sharing with us some code snippet to help us to troubleshoot this issue?
    If not, I suggest you posting it to
    Word IT Pro Discussions get more effective responses.
    Best regards
    Fei
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • How do I set a fixed page size in Muse so that the window always stays the same size

    how do I set a fixed page size in Muse so that the window always stays the same size

    Hi Aish & thanks for responding;
    I would like the window size to stay the same for the entire site and not be
    able to scale to drag & scale it. ie 950 pixels x 500 pixels.
    Thanks,
    JB
    On 12/4/14 3:30 PM, "Aishvarya Raj Rastogi" <[email protected]>

  • Panel doesn't display properly until I resize the frame

    Hiya folks,
    I'm currently trying to write a simple piece of music notation software. This is my first time using swing beyond a relatively simple JApplet and some dialog stuff. Anywho, I ran into a pretty discouraging issue early on. So far I've got a frame with a menu bar and a toolbar on the bottom border. The toolbar contains a button which should draw a new staff panel containing 11 panels (potentially more) within it, alternating between lines and spaces. Sort of like this:
    import javax.swing.*;
    import java.awt.*;
    public class Staff extends JPanel {
       private static JPanel nsp1,nsp3,nsp5,nsp7,nsp9,nsp11;
       private static JPanel nsp2,nsp4,nsp6,nsp8,nsp10;
       private ImageIcon image= new ImageIcon(this.getClass().getResource( "icons/treble clef.gif"));
        public Staff(){
        setLayout(new GridLayout(11,1));
        add(nsp1= new NoteSpace());
        add(nsp2= new LineSpace());
        add(nsp3= new NoteSpace());
        add(nsp4= new LineSpace());
        add(nsp5= new NoteSpace());
        add(nsp6= new LineSpace());
        add(nsp7= new NoteSpace());
        add(nsp8= new LineSpace());
        add(nsp9= new NoteSpace());
        add(nsp10= new LineSpace());
        add(nsp11= new NoteSpace());
    static class NoteSpace extends JPanel{
        public NoteSpace(){
        setPreferredSize(new Dimension(this.getWidth(),2));
    static class LineSpace extends JPanel{
          public LineSpace(){
          setPreferredSize(new Dimension(this.getWidth(),1));
          public void paint(Graphics g) {
              super.paint(g);
              g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
    }Anyway, this panel displays as a tiny box wherein nothing is visible until I resize the frame. Really frustrating. And I have have no idea what the problem might be. Here's the actionlistener:
    jbtcleff.addActionListener(new ActionListener (){
            public void actionPerformed (ActionEvent e){
                staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
                panel.add(staff);
                staff.repaint();
            });...which is located in a custom jtoolbar class within the Main class, an extension of JFrame:
    public class Main extends JFrame{
       JMenuBar jmb=new CustomMenuBar();
       JToolBar jtb= new CustomToolBars("ToolBar");
       static boolean isStaff=false;
       static boolean isNote=false;
       static JPanel panel = new JPanel();
       private static Staff staff= new Staff();
        private static Toolkit toolkit= Toolkit.getDefaultToolkit();
       private static Image image=toolkit.getImage("C:/Users/tim/Documents/NetBeansProjects/ISP/src/MusicGUI/icons/treble clef.jpg");
        private static Cursor noteCursor = toolkit.createCustomCursor(image,new Point(0,0),"Image"); 
       public Main (String m) {   
            super(m);
            setJMenuBar(jmb);    
            getContentPane().add(jtb,BorderLayout.SOUTH);       
            panel.setLayout(new CardLayout(60,60));
            getContentPane().add(panel);
    public static void main (String[]args){
            JFrame frame= new Main("Music");
            frame.setSize(800,400);
            frame.setLocationRelativeTo(null);
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.setVisible(true);
            frame.setIconImage(image);
           Sorry for all the code. I'm desperate.
    Thanks!

    Oh my... have you been through the Swing tutorial?
    Let's look at some of your code,
    static class NoteSpace extends JPanel{
        public NoteSpace(){
        setPreferredSize(new Dimension(this.getWidth(),2));
    static class LineSpace extends JPanel{
          public LineSpace(){
          setPreferredSize(new Dimension(this.getWidth(),1));
          public void paint(Graphics g) {
              super.paint(g);
              g.drawLine(0, (int) super.getHeight()/2, (int)super.getWidth(), (int)super.getHeight()/2);
    }Here, NoteSpace and LineSpace are being set to a preferred size of 0x2 pixels, and 0x1 pixels respectfully. If you want them at 0 width, how do you expect them to show? In particular, NoteSpace isn't doing anything special. It's just a panel. Why an inner class? Lastly you should not override paint() for SWING. That's AWT stuff. For Swing, you override paintComponent(Graphics g) .
    Then we have this
    jbtcleff.addActionListener(new ActionListener (){
            public void actionPerformed (ActionEvent e){
                staff.setBounds(50,panel.getHeight()/2,panel.getWidth()-50,panel.getHeight()/2);
                panel.add(staff);
                staff.repaint();
            });I'm not sure what the variable jbtcleff is, but it seems you are adding your Staff panel to "panel" every time a button is pressed.... why? Why not just add it once (outside the action listener) and be done with it. Your panel object has a CardLayout, so I assume you meant to create a new+ staff panel everytime a button is pressed, and then add it to the card layout panel. Even so, setBounds(...) does not seem pertinant to this goal. (In fact, in most situtations the use of setBounds(...) is the antithesis of using layout managers).
    The problem you mentioned though seems to be related to the use of a JPanel (your Staff class) that adds zero-width compontents to a grid array.

  • I resized the window to 150% and now I can't get it back to 100% view and keep it that size. How do I get it back to the right size?

    I resized the adobe window to 150% and now I can't get it back to the 100% size and keep it that size. How do I get the original 100% back and keep it that size?

    Hi Linda,
    To control the page zoom option you can also go to Edit> Preferences> Page Display.
    Regards,
    Rave

  • Why are the video player change size when resizing the window a little?

    When I use the video player to show mp4 files, the "player window" changes size if I change the firefox window. Why and how do I do to get the correct size direct (640x480)

    Hi john3,
    This can be the resolution of the screen or the site detecting screensize, do you have a url we can take a look at to determine what's going on?
    Thank you!

  • Why Apple ignored Ethiopia with population size of 100 million in the countries list.

    EThiopia Avery big country and population is not in the list of Apple store countries.we are one of the fastest developing country with population size of 100 million
    apple need to correct this big mistake

    The GDP of Ethiopia is $1,300 per capita, per year and it ranks 211th in the world. Since Apple is a commercial enterprise, it would be strange to offer a product that costs most of the annual income of an average person.
    I sincerely hope that it does continue to develop to the point that companies like Apple would be interested in opening stores.
    George

  • Wallpaper size changes when i press the home button

    if i press the home button after setting a wallpaper, it zooms really close in and ruins the picture, how can i fix this please?
    Solved!
    Go to Solution.

    http://userguide.sonymobile.com/referrer.php?region=global-en&product=xperia-z1#!Background-and-them...
    Follow Documents

  • Pannel size not adjusting according to the window size

    can anybody solve my problem
    in my application in a tab i have tree pannels,
    the central panel is agian divided into two pannels (left and right).
    the application when loaded it shows proper layout but when maximized the space for right side pannel increased but the pannel is not compleately filled in it .
    That is : right side pannel is leaving some space at its left which is looking very untidy.
    please anybody suggest how to adjust the size of pannel according to window size.
    abhithewizard

    can anybody solve my problem
    in my application in a tab i have tree pannels,
    the central panel is agian divided into two pannels (left and right).
    the application when loaded it shows proper layout but when maximized the space for right side pannel increased but the pannel is not compleately filled in it .
    That is : right side pannel is leaving some space at its left which is looking very untidy.
    please anybody suggest how to adjust the size of pannel according to window size.
    abhithewizard

  • On job application sites, when I submit, a window opens in encrypted code instead of text. How do I change this to allow the window to display text?

    On the various steps to an online job application, when I click on submit, instead of a window with a text file popping up a window pops up with html or computer coding instead of text. How do I change this so I can properly utilize these site processes. I looked for the setting that allows both html and text and it is set to do so.

    What is the content of that window?
    Can you attach a screenshot?
    *http://en.wikipedia.org/wiki/Screenshot
    *https://support.mozilla.org/kb/how-do-i-create-screenshot-my-problem
    *Use a compressed image type like PNG or JPG to save the screenshot
    *Make sure that you do not exceed the maximum size of 1 MB
    Start Firefox in <u>[[Safe Mode|Safe Mode]]</u> to check if one of the extensions (Firefox/Tools > Add-ons > Extensions) or if hardware acceleration is causing the problem.
    *Switch to the DEFAULT theme: Firefox/Tools > Add-ons > Appearance
    *Do NOT click the Reset button on the Safe Mode start window
    *https://support.mozilla.org/kb/Safe+Mode
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes

  • How do I re-size a layer without resizing the background I am pasting it on?

    I have a certain sized jpeg file (3648 pixels X 1368 pixels) that I want to use as a canvas to place smaller jpeg files on.  The problem is, the "smaller" jpeg files are actually bigger.  Rather than shrink them down individually and then paste on the canvas, I would like to copy them onto the canvas and then shrink them (this will allow me to more easily compare their size to the other photos as I'm shrinking them).
    Is there a way to do this in Adobe Photoshop?

    When you say "Grab the corner handle and drag smaller" I know what you mean since this is how I would do it using MS Paint.
    The problem is, I don't get a corner handle to show up.  If I hold down the Shift key, it merely prevents me from seeing the movement until the movement is complete (i.e. as I move the 2nd image where I want it, the screen automatically shows where it is being moved to whereas holding down the shift key merely moves an outline around which, once the shift key is released, becomes the location of the 2nd image).
    I should mention that I am using a Mac and not a PC.  Is that why there is no corner handle to grab?

  • How Do I Change Trackpad Settings on the "Windows" Side of the MBA?

    Happy to report that I succesfully installed Windows XP on my MBA SSD. However, I can't seem to find the options in Windows XP to change the trackpad settings (e.g., click with touch, speed, etc.). I see mouse, keyboard, etc. settings but no touch/track pad. Any direction would be much appreciated.
    Thanks in advance!

    My understanding is there is no hardware driver written for windows side for the hardware in the MBA. I wish there was, I love my MBA - but I use it primarily as a windows XP machine.

  • How can I resize the window size of my website?

    My site is
    http://linguistine.com/
    I put the swf in a html page but i'd like the window to be
    the dimensions of the swf not the html page. Is there an easy way
    to do this?
    Thanks
    Jamie

    Hi, not sure about your question, but, I would like to say
    that I think the design work in the site is really good. I do know
    that in Dreamweaver, this sort of issue would be handled by using a
    javascript in 'Behaviours', maybe the same exists in Flash. Can't
    check as I am on Flash 7 and would guess you are 8 or 9.
    Regards Jonathan

  • Preventing scrollbars appearing when font size changes

    Hi,
    I have a Panel container (relative layout with now height/width specified) containing text which has its font size determined at runtime from an external stylesheet. In my application, the user has the option to change font size (ie. load a separate external stylesheet). The problem is, whenever larger font sizes are chosen, horizontal and vertical scroll bars keep appearing within my panel container. I do not want this at all, I want the panel to resize!
    I've tried almost everything, including:
    Calling "validateNow()" when font size changes
    Launching a resize event when font size changes
    Overriding the updateDisplayList method of Panel and trying to set the height and width to the newly measured height and width.
    None seem to be effective. It is as if the Panel does is not able to calculate the new size when the font size changes.
    Any help would be GREATLY appreciated.
    Thanks.

    Hi,
    With mx panel you can set its verticalScrollPolicy="off" horizontalScrollPolicy=""off",
    David.

Maybe you are looking for

  • How do I insert a flyer made in Photoshop into the body of an email...

    I made a flyer in Photoshop, I saved it as a JPG. Then I went into my email client AOL to insert it into the body of the email to send out to my clientele. I sent it to myself first to check the resolution etc. The problem is I cannot get it to keep

  • Regarding smart forms (really urgent)

    hi, i am new to smartforms and i got report to make changes in the smart forms,plzz help me out as i know nothing about the smart forms by providing me it in easiest & simplest form. if find useful help will be deifnately rewarded. Edited by: ric .s

  • How to make a really basic alleyway for a beginner

      Hello,I am a student making a project related to games and I picked an alleyway.I've read through a couple of threads on here dealing with making a game of alleyway in LabView.I a still a newbie and I am asking for some guideance inorder to be able

  • Critical_Structure_Corruption Error with Windows 8.1

    Hello, I have recently upgraded windows 8.1 on my six months old Dell Inspiron 14 5423 laptop. It was fine until yesterday, But from yesterday i have started facing issues, System is going down for every one hours, Critical_structure_corruption error

  • Generating cash flow statement

    Dear friends We need to generate cash flow statement as per the accounting standard.How to get that. Again if it is not possible to generate as per accounting standard then pl. tell in the normal way. Thanks Shivaji