problems with fixing ScrollPaneLayout

I use a patch of a former subject of mine (Re: rather confusing behavior get with BorderLayout provided by Walter Laan (thanks!), but I just came across some problems with it.) The code below is almost identical to the solution on the former thread:
import java.awt.*;
import javax.swing.*;
 
public class TestScrollPaneLayout {
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                final JFrame frame = new JFrame("Test");
                
                // use BorderLayout if you don't want the borders
                final JPanel myPanel = new JPanel();
                myPanel.setBorder(BorderFactory.createLineBorder(Color.pink));
                myPanel.add(new JLabel(
                "A nice label, oh wait its too long! (actually its too short, hence why i am adding this)"));
 
                final JScrollPane scroll = new JScrollPane(myPanel,
                        JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scroll.setLayout(new FixScrollPaneLayout());
               
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(new JLabel("Resize the frame to show/hide the scroll bar"),
                        BorderLayout.PAGE_START);
                frame.getContentPane().add(scroll,
                        BorderLayout.PAGE_END);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    }
    
    public static class FixScrollPaneLayout extends ScrollPaneLayout {
        @Override
        public Dimension preferredLayoutSize(Container parent) {
            Component view = getViewport().getView();
            if(!(view instanceof Scrollable)) {
                // if not Scrollable ViewPortLayout sets an explicit size
                // which means ScrollPaneLayout ignores the view preferred size
                // this workaround assume this is only called during layout
                getViewport().setViewSize(view.getPreferredSize());
            }
            Dimension size = super.preferredLayoutSize(parent);
            if ((hsb != null) && (hsbPolicy != HORIZONTAL_SCROLLBAR_NEVER)) {
                if (hsbPolicy == HORIZONTAL_SCROLLBAR_ALWAYS) {
                    // size is OK
                }
                else {
                    boolean canScroll = true;
                    if (view instanceof Scrollable) {
                        canScroll = !((Scrollable)view).getScrollableTracksViewportWidth();
                    }
                    if (canScroll) {
                        Dimension viewSize = getViewport().getViewSize();
                        Dimension extentSize = getViewport().getPreferredSize();
                        if(viewSize.width > extentSize.width) {
                            // size is OK
                        }
                        else if(view.getPreferredSize().width > getViewport().getWidth()) {
                            // Fix it!
                            size.height += hsb.getPreferredSize().height;
                        }
                    }
                }
            }
            return size;
        }
    }
}
However, if I start adding the fixed scroll pane in other places (for example, in a Panel in the footer) instead of just the borderlayout within the framework:
public void run() {
                final JFrame frame = new JFrame("Test");
                
                // use BorderLayout if you don't want the borders
                final JPanel myPanel = new JPanel();
                myPanel.setBorder(BorderFactory.createLineBorder(Color.pink));
                myPanel.add(new JLabel(
                "A nice label, oh wait its too long! (actually its too short, hence why i am adding this)"));
 
                final JScrollPane scroll = new JScrollPane(myPanel,
                        JScrollPane.VERTICAL_SCROLLBAR_NEVER,
                        JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
                scroll.setLayout(new FixScrollPaneLayout());
                
                JPanel footerPanel = new JPanel();
                footerPanel.setLayout(new BorderLayout());
                
                footerPanel.add( scroll, BorderLayout.PAGE_START);
                footerPanel.add(new JLabel("footer : made by me!") , BorderLayout.PAGE_END);
                
                frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
                frame.getContentPane().add(new JLabel("Resize the frame to show/hide the scroll bar"),
                        BorderLayout.PAGE_START);
                frame.getContentPane().add(footerPanel,
                        BorderLayout.PAGE_END);
                frame.pack();
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
I get strange when behavior its maximized/minimized. In my program real when I maximize and print the statement:

If (view.getPreferredSize () .width > parent.getWidth ())

parent.getWidth () is not just, its allways the unmaximised (if you maximize) size or vice versa and only attaches to a manual resizing or revalidate/repaint, this isn't what happens in the example above, but his strange behavior still display...

I hope someone can help track down the problem

Thank you

Edition - to clarify only upward acts when optimize you a size that has a scroll bar or reduce to this dimension

You might want to try using revalidate():

frame.addWindowStateListener(new WindowAdapter() {
  @Override public void windowStateChanged(final WindowEvent e) {
    EventQueue.invokeLater(new Runnable() {
      @Override public void run() {
        System.out.println("windowStateChanged");
        JFrame f = (JFrame)e.getWindow();
        ((JComponent)f.getContentPane()).revalidate();
      }
    });
  }
});

Tags: Java

Similar Questions

  • Problem with fixing XP files permissions

    Hi all

    I am having some problems with the permissions of the files on my Windows XP laptop. The crux of the problem is that I can't copy/move/delete some files even if ownership and file permissions are all correctly. Even within a directory, some files I can move/copy, but others I can't. The files in question are my Outlook PST files which I am trying to back up manually.

    I tried to play with file ownership and permissions. Used the account admin machine, all to nothing does not. There is no file open file handles, I can not simply copy them. It's all very strange and hope someone can suggest how I might be able to gain control of these files again.

    Thank you.

    Mark

    Please describe your problem in detail. Include the full text of any error messages you see. Tell us the brand and model of the PC and what version of XP (Home, Pro, or MCE) runs as well as the Service Pack level.

    Outlook PST files can only be saved when Outlook is closed.

    Also, it is unlikely, but do a right click on the PST file, select properties from the context menu, and uncheck the 'Read only' if it is checked. Click OK

    Hope this helps

    Post back if necessary

    ____________________

    If this post can help solve your problem, please click the 'Mark as answer' or 'Useful' at the top of this message. Marking a post as answer, or relatively useful, you help others find the quick answer

  • Problems with fixing the elements to my email.

    My email Outlook Hotmail don't fix anything.  I get a message that says that the internet does not work and needs to close.  Everything else works fine, and I have no virus.  Has anyone else had a similar problem?

    Hi Connie,

    1. are you using Internet Explorer? If Yes, what version of internet Explorer do you use?
    2. you have any third-party antivirus installed on the computer program?
    3. What is the size of the attachment that you are trying to reach?

    This problem may occur if the size of the attachment is too large, because of the antivirus or a third-party program causing the problem.

    How to optimize Internet Explorer
    http://support.Microsoft.com/kb/936213/ro

    Note: Reset the Internet Explorer settings can reset security settings or privacy settings that you have added to the list of Trusted Sites. Reset the Internet Explorer settings can also reset parental control settings. We recommend that you note these sites before you use the reset Internet Explorer settings.

    Keep us updated on the status of the issue.

  • problem with fix each site loading on olmost

    some pages do not appear, some do, but on a level sup of the page which makes then not load page is random on most of the Web pages I prefer to visit on the microsoft site that there is a udatate for this problem, but only for 10 windows, I use windows 7 and firefox

    sincirely your Holland Tijmen, Hattem

    As the problem seems to be with all the web pages, try this;

    Location of cache files; Windows: * C:\Users\\AppData\Local\Mozilla\Firefox\Profiles\------Mac: ~/Library/Caches/Firefox/Profiles/ Linux: ~/.cache/mozilla/firefox/

    Close Firefox. Open your file browser to the above and delete the folder.

  • Problems with fixing e-mail signatures

    I've just upgraded to El capitan. Now, I can not join a signature because the signature area choose is grayed out; there is no signature to the choice. I reinstalled two signatures that I want to use but no luck so far. Any suggestions?

    Diane,

    You have the correct email account selected for the desired signature? Mail (El Capitan): Signatures preferences:

    "Choose to work with signatures by clicking on all Signatures or an e-mail account."

  • When Apple will fix the problem with 9.3?

    Since IOS 9.3 was just downloaded (night of 26 March) and not yet installed, my iPad (Wifi and boxes) Air did not work properly:

    By clicking on a link in GMAIL or AOL emails causes the iPad to freeze.

    Safari does not work.

    Chrome does not.

    When I tried to install the update already downloaded 9.3, the installation did not check because I was "not connected to the internet."

    On Monday, March 28, I noticed many others had similar problems with 9.3, and I tried the recommended fixes:

    Disable Java Script

    Remove Booking.com

    Delete web browsing data

    Restart the iPad.

    None of these bugs worked.

    Tuesday morning, March 29, the Update 9.3 installed correctly, but none of the symptoms have been set.

    I refuse to downgrade to a version 9.2 based on serious disadvantages noticed by others who have tried it.  Besides, why should I do an Apple problem be my problem?

    When will this problem be resolved?

    MJSF wrote:

    When will this problem be resolved?

    No one here works for Apple (and anyone who works for Apple would be bound by an NDA), there is no way to answer this question. You will have to just be patient.

    The update that was released was for something different and more critical.

  • seems I'm not the only one having problems with safari after update 9.3 cannot follow the links. Safari blocks. hope it gets fixed quickly. jaa shooting allows to follow the link, but the Web page is not out of good old days. any oher ideas?

    seems I'm not the only one having problems with safari after update 9.3 cannot follow the links. Safari blocks. hope it gets fixed quickly. jaa shooting allows to follow the link, but the Web page is not out of good old days. any oher ideas?

    The 'list' of relevant articles that I know, they are now

    -You can read about the problems in the present statutes and possibly find workaround solutions, particularly in the last

    If you are unable to activate your iPhone, iPad or iPod touch after installing an update - Apple Support

    Apple iOS suspension 9.3 updates for older devices, work on activation fix | IVous

    Apple launches new version of iOS for iPad users 9.3 2 affected by bricking bug | 9to5Mac

    GSM of unfixed addresses Apple iPad 2 Bug with revised Activation iOS 9.3, but the larger question remains - Mac rumors

    If you are unable to activate your iPad 2 (GSM model) update to iOS 9.3 - Apple Support

    9.3 iOS update issues

    Leave a post by: ChitlinsCC

  • I have a problem with error 53.I know this mistake is for people who have their iPhones fixed by a third party before, the thing is my iphone 6 was never taken to a third party before, so all opinions

    I have a problem with error 53.i have 6 + and I m out of warranty. I know this error is for people who have their iPhones fixed by a third party before, the thing is my iPhone 6 + was never taken to a third person before, error 53, it isn't my fault .i was going to do a upgrade to the new version

    All view of what can be done

    If your device is outside its warranty, you can always make an appointment at the Apple Genius Bar to have the studied unit. 53 error will also occur if there is other material errors that are not defined on the device. One of them has to do with contact IDS. Your Touch ID was never working, or did it stop working? Have you had damage to the device by dropping, water damage or damage to the 'home' button?

    Apple can examine the device and determine your options. You will also be flooded with other options for independent repair facilities, however before turn you to this, understand that their work on your device will void any support post-warranty Apple, and there is no way of knowing that the qualities of these repair facilities, as they are not certified by Apple, as Apple does not certify independent repair facilities. If you decide to go this route, be sure to only find a way to check the reviews, etc..

  • I have problems with my iTunes account, I can't sign on the App Store and change my password, how can I fix it?

    I have problems with my iTunes account, I'm unable to download apps from the app store or any other product related to Apple. I changed my password and still does not work. How can I fix it?

    How and when did you try to connect for example you just enter the new password when you try to download something, or if you have completely connected exit since the change of the password and try to connect again: what to do when you have changed your Apple ID email address or password - Apple support ?

  • How can I fix a problem with AlerteGPS_G520

    Hello here is my question...

    How can I fix a problem with AlerteGPS_G520

    Hello
    I suggest you contact the manufacturer of the product.
    Be sure to provide all the details.
    b Eddie

  • Sorry, there is a problem with Hotmail right now. It should be fixed soon, so please try again in a few minutes. "- How to fix?

    When I try to click in and see my emails it says "sorry, there is a problem with Hotmail right now. It should be fixed soon, so please try again in a few minutes. "and mails never appear (I could see it on the list, but could not click on it to see it), but it has been like that for more than 48 hours, please help!

    Hello

    Answers is a peer group supported and unfortunately has no real influence on Hotmail.

    HotMail has its own Forums, so you can ask your questions there.

    Windows Live Solution Center - HotMail - HotMail Forums Solutions
    http://windowslivehelp.com/

    Hotmail - Forums
    http://windowslivehelp.com/forums.aspx?ProductID=1

    Hotmail - Solutions
    http://windowslivehelp.com/solutions.aspx?ProductID=1

    How to contact Windows Live Hotmail Support
    http://email.about.com/od/hotmailtips/Qt/et_hotmail_supp.htm

    Windows Live Hotmail Top issues and Support information
    http://support.Microsoft.com/kb/316659/en-us

    Error message "your account has been locked" when trying to connect
    http://windowslivehelp.com/thread.aspx?ThreadId=77be7d82-a0e9-49c7-b46d-040ec654a9e2

    Compromised account - access unauthorized account - how to recover your account
    http://windowslivehelp.com/solution.aspx?SolutionID=6ea0c7b3-1473-4176-b03f-145b951dcb41

    Hotmail hacked? Take these steps
    http://blogs.msdn.com/b/securitytipstalk/archive/2010/07/07/Hotmail-hacked-take-these-steps.aspx

    I hope this helps.

    Rob Brown - Microsoft MVP<- profile="" -="" windows="" expert="" -="" consumer="" :="" bicycle="" -="" mark="" twain="" said="" it="">

  • Why my email say 'sorry, there is a problem with Hotmail now. We are working hard to fix, but it may take a little time yet. »

    Why my email say 'sorry, there is a problem with Hotmail now. We are working hard to fix, but it may take a little time yet. »

    Hello

    The question you posted would be better suited to Windows Live Solution Center. I suggest you to send your application in the Windows Live Solution Center for better support.
     
    http://windowslivehelp.com/product.aspx?ProductID=1

  • My Windows Live Hotmail contacts are missing: "sorry, there is a problem with Hotmail right now. It should be fixed soon, so please try again in a few minutes. »

    Cannot get Hotmail contacts.  Error message States "he has a problem with Hotmail right now. It should be fixed soon, so please try again in a few minutes. "The first sentence is repeated in the great blue and and then more small black font.  Then he gives a link "tries to return to Hormail.  It has been so since then, I believe, before Christmas. I can get my hotmail emails, my Windows Live ID page comes up, just no contacts.  Fortunately, my windows phone keeps my contacts.  I also use Outlook Connector, which synchronize my outlook, hotmail, and LinkedIn contacts nicely, but the hotmail contacts have disappeared.

    Hi GtoddG,

    Thanks for posting your question in the Microsoft answers Forum. For any question on Hotmail, please visit the following link:

    http://windowslivehelp.com/forums.aspx?ProductID=1

  • If win 2003 is upgraded for the 2008 edition, it will fix alingment compensate for the problem with the SAN disks?

    If win 2003 is upgraded for the 2008 edition, it will fix alingment compensate for the problem with the SAN disks?

    Hi elvirkaric,

    Your question in Windows Server 2008 is more complex than what is generally answered in the Microsoft Answers forums. It is better suited for the IT Pro TechNet public. Please post your question in the TechNet Forum. You can follow the link to your question:

    http://social.technet.Microsoft.com/forums/en-us/w7itproinstall/threads

  • I have problems with the installer of Windows and Windows Update, and the solutions that I found for the two each rely on the other broken system to fix the first.

    I use a laptop HP Pavilion dv4-1220us with Windows Vista Home Premium Service Pack 1, a 64-bit operating system, and I have problems with Windows Update and Windows Installer. When I try to install programs, I get the following, or substantially similar message without the error code:

    "Error 1719. The Windows Installer Service could not be accessed. This can occur if Windows Installer is not installed properly. Contact your support team. »

    So I tried to download Windows Installer 4.5 and install it. When I try to start the installation, it always hangs on the first step, "Initializing Installation."

    After searching for a solution to this problem, I found that Windows Update may have a solution. So I downloaded the 64 bit version and got a file named 'file Windows6. 0-KB942288-v2 - x 64. I tried to run this file. He opened a box that said, in order "Prepare for Installation", "Full Preparation", and finally "Searching for Updates ', before you open a second box, which reads" click OK to install the following Windows software update: fix for Windows (KB942288). I clicked on OK in this box, which opened another box, which says at the top "updates are installed" and in a smaller section, "initializing for Installation................... »

    However, no matter how long it works, it never gets past "Setup initialization."... »

    So I tried to run Windows Update in Control Panel. He ran for a while, before giving a message saying "to check the updates, you must first install an update for Windows Update." I clicked on the button that says "install now". He has flashed, a moment, "download and installation of updates' before you go to the"check for Updates"and then he brought back the exact same upward ' to check updates, you must first install an update for Windows Update" message as before. I clicked install now once again, only to go into the exact same loop. After about four times in a loop, I gave up on it.

    So I tried to install Windows Installer 3.1v2, which took a while before saying "not enough memory is available to process this command." and the abandonment of the installation.

    So, I tried to download a program from 'Mr. Fix - it' of Microsoft. It downloaded fine and then failed on installation, because of the same Setup error I received initially.

    Finally, I tried to restart my computer and each solution is represented. Then I clean my computer and each solution is represented.

    In conclusion, the mistakes that I have in Windows Update and Windows Installer cordoned off each other, as the mistakes of each program are based on the other program to be repaired. I'm at my wit's end here. My computer works fine without one, except that I can't install new programs. I can access the internet fine, access files fine, all my scans have developed own... I don't really know what is happening. Can someone help me with this?

    Try the sfc scan:
    http://support.Microsoft.com/kb/936212

    If not, repair of Vista:
    http://www.Vistax64.com/tutorials/88236-repair-install-Vista.html

Maybe you are looking for