JScrollPane with scrollbar as needed packs to the wrong size.

Hi!
I just noticed a strange problem when packing a JScrollPane with scrollbar policy "as needed" and wondered if it's me or if it is a real bug in Swing.
I create a JFrame with a JScrollPane in it and a JPanel as viewportview. The JPanel (called "stuffPanel") contains a few components which give it a preferred size, and the JScrollPane is set to grow as needed if the window grows. A button in the center of the stuffPanel will invoke pack() on the window when clicked.
Now, if I resize the window such that the JScrollPane can't display the entire stuffPanel, I get scrollbars as expected. If I click the pack button the window correctly resizes to the preferred size (without scrollbars).
On the other hand, if I resize the window to become larger than the preferred size and then click the pack button, the window (and the stuffPanel) is resized to include 17 pixels of extra size around the edges.
Put simply, pack() will resize the JPanel to different sizes depending on whether the scrollbars of the JScrollPane were visible at the time. Note that this only occurs when you're using the "scrollbars as needed" scrollbar policy.
An even more interesting situation occurs if you resize the window to include (for example) only horizontal scrollbars and then packs the window repeatedly...
Code for a Java app which displays the strange behaviour is included below:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TestJScrollPane {
  static {
    try {
      UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    catch (Exception e) { }
  private JFrame mainWindow;
  public TestJScrollPane() {
    mainWindow = createMainWindow();
    mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainWindow.pack();
    mainWindow.show();
  public JFrame createMainWindow() {
    JFrame window = new JFrame("Test of scrollpane");
    window.getContentPane().setLayout(new GridBagLayout());
    final JPanel stuffPanel = new JPanel();
    stuffPanel.setBorder(BorderFactory.createTitledBorder("Collection of stuff"));
    stuffPanel.setLayout(new GridBagLayout());
    JLabel stuffLabel = new JLabel("A label");
    JTextField stuffField = new JTextField(10);
    JButton stuffButton = new JButton("Pack the window");
    JList listOfStuff = new JList();
    listOfStuff.setListData(new String[] {"Fish", "Bird", "Mammal", "Insect", "Spider"});
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    stuffPanel.add(stuffLabel, gbc);
    gbc.gridx = 1;
    stuffPanel.add(stuffField, gbc);
    gbc.gridy = 1;
    gbc.gridx = 0;
    gbc.gridwidth = 2;
    stuffPanel.add(stuffButton, gbc);
    gbc.gridy = 2;
    gbc.fill = GridBagConstraints.BOTH;
    stuffPanel.add(listOfStuff, gbc);
    final JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroller.setViewportView(stuffPanel);
    gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.BOTH;
    gbc.weightx = 1;
    gbc.weighty = 1;
    window.getContentPane().add(scroller, gbc);
    stuffButton.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent e) {
        mainWindow.pack();
        System.out.println("Stuff panel size: " + stuffPanel.getSize());
        System.out.println("Stuff panel preferred size:" + stuffPanel.getPreferredSize());
        System.out.println("Scroller size: " + scroller.getSize());
        System.out.println("Scroller preferred size: " + scroller.getPreferredSize());
    return window;
  public static void main(String[] args) {
    new TestJScrollPane();
}

Why would the JScrollPane be as big as the entire
frame when you added 800x600 panels on all sides of
it? It's going to be in the center surrounded by
huge panels. Thanks, kablair. However, if you look at the code, these panels are not 800x600 on all sides. The north and south panels only add a combined height of 100, and the east and west panels only add a combined width of 100. so the whole window, minus insets, should be 900x700.
Anyway, i took the advice of the guy above, and that has gotten me much closer. In the bigger app that I'm trying to calculate the size, now I'm only 2 pixels away from the true size, although I can't figure out what I'm forgetting.

Similar Messages

  • I am trying to make a pdf of a file and I need to get the file size to be no bigger than 10MB. What is the best way to do this

    I am trying to make a pdf of a file and I need to get the file size to be no bigger than 10MB. Even when I save it, the image quality at minimum the file size is 10.9 MB. What is the best way to do this

    @Barbara – What purpose is that PDF for? Print? Web?
    If web purpose, you could convert CMYK images to sRGB. That would reduce the file size as well.
    A final resort to bring down file size is:
    1. Print to PostScript
    2. Distill to PDF
    That would bring file size down even more. About 20%, depending on the images and other contents you are using, compared with the Acrobat Pro method. If you like you could send me a personal message, so we could exchange mail addresses. I could test for you. Just provide the highres PDF without any downsampling and transparency intact. Best provide a PDF/X-4.
    I will place the PDF in InDesign, print to PostScript, distill to PDF.
    Uwe

  • Need to reduce the page size, not the file size (shrink the page to allow for binding)

    I need to reduce the image size (text is too large to allow for binding).

    What is the output device - it is best to set scaling there, or scale while printing from Acrobat. The only means to accomplish
    I need to reduce the image size (text is too large to allow for binding).
    Print to Adobe PDF printer.
    Define a page size in the Properties of the PDF Printer
    Print from Acrobat to PDF Printer with scaling in effect.

  • Do I need to reduce the images size in pixels before upload them to M.Me?

    Do I need to reduce the images size in pixels (actual size jpeg 5616 × 3744 pixels/766kb) before upload them from iPhoto to a Mobile Me Gallery?
    Otherwise they will be heavy or the upload process take care of that?
    It would be nice that iPhoto took care and optimize the images to display online without any more work, because I´ve 1200 images to upload and they´re jpegs 5616 × 3744 pixels. It´s just to viewing purposes. Not o download or print.
    Thanks.

    In fact no matter if I use a High or Medium compression size JPEG, the size after upload is the same.
    Starts with 1,5 MB/5600px (high) or 780kb/5600px (medium) JPEG and ends after upload in 115kb for a 1024px image.
    This means that iPhoto auto compress in order to publish to Mobile Me, even if we start with a bigger file.
    I hope this info is useful to others.
    Thanks.

  • Need to increase the font size of SAP printer

    Hi all,
    We had some new HP printers HP4015 which needs to print from SAP . we created the new device type ZHPLJCM1 after checking correct device type for it from HP printer site. For some users printouts are coming in small fonts ,they wanted it to print in big fonts .
    These are some of the  t codes  that they use KAH3 , FB03 , Y_DEV_39000067.
    we tried to change the printer fonts in SE73 of that particular device type and increased the font size , but that also ended in vain.
    Kindly suggest possible ways by which we can solve this issue.
    Please let me know if more information are needed.

    Hi,
    Is this ABAP lists, sapcript or smartforms? For sapscript or smartforms, you need to specify the font size in the paragraph/character formats for sapscript and in the smartstyle for smartforms.
    For ABAP lists, the font size is selected based on the format used. e.g. If you create a list with format X_65_255, it should print in landscape and the font size is calculated based on the size needed to fit 255 characters into a page. If the format is X_65_132, then the font size is calculated based on the size needed to fit 132 characters into a page so it is a bit larger.
    Regards,
    Aidan

  • Need to Increase the Font Size of a screen field in a Dialog Screen ?

    Hi ppl,
    I have a requirement wherein i need to increase the font size of one field on a dialog screen .
    i was going through the threads and found this which has beautiful example given by vijay
    Increase text size in Screen
    But I'm facing a problem in implementing it since the value in the field (of which the font size needs to be increased) depends on a nother field filled by user at runtime only.
    Can anyone gimme some suggestions or alternative way to solve my problem
    Thanks
    Sachin Soni

    Hi Sachin,
    There is not way to change the font style.
    But you can add ur own text through icons or graphics.
    Create your own graphics or icons and include it in ur module pool.
    Or,
    Goto the Layout Editor of your Screen.
    Double click on the text field .. Double clk the text fild, and from the Botton right u can see an arrow icon -> click on that -> will open a Popup -> in that set Area Title to TRUE.
    Hope this solves your problem.
    Thanks & Regards,
    Tarun Gambhir

  • AEX CS3 error  {SetOutputWorld called with a world of the wrong size}

    I am getting the following message:
    After Effects error: internal verification failure, sorry! {SetOutputWorld called with a world of the wrong size}
    ( 78 :: 4 )
    Any suggestions?

    Check this:
    http://aeerrors.myleniumstuff.de/?p=547
    Beyond that, you will have to provide more info on what you actually do. Could be a couple of things from the CoDec issues mention in my collection to outdated plug-ins doing something weird...
    Mylenium

  • Site previews fine in Firefox locally, but when I published the site all the text is the wrong size

    I am a rookie web designer. I recently created a site using CS6. http://www.joshuahetzler.com When I previewed the site in Dreamweaver it looked good in Firefox and IE. I published the site and now it is messed up in Firefox. All the text is the wrong size. Does anyone know how to fix this? Does it have something to do with my hosting provider? (I deleted a wordpress site from the directory an hourago and put this new site in its place) Why does IE display properly, but not Firefox...

    Caused by a bad link to your site's CSS file.  This is pointing to a file on your local hard drive which nobody but you can see.
    <link href="file:///C|/hetzlerj/jhgc/menu.css" rel="stylesheet" type="text/css" />
    Open your template and reconcile the path to your site folder.  It should probably look like this:
    <link href="../menu.css" rel="stylesheet" type="text/css" />
    Save Template.  Populate changes to Child pages.  Upload Child pages.
    Nancy O.

  • Can I change the size of my iphoto book, when I am ready, but changed the wrong size

    Hallo,
    after several weeks work with my iphoto book, I discover, that I choosed the wrong size.
    I choosed  the size- "large book" instead of   XL book 33x31 cm .
    Can I change or have I do do the work twice.
    Many thanks
    itaenzer

    select the book in the source pane on the left and duplicate it (command-D) and then click on the themes button and select the new size/style/theme  --  closely inspect the book to be sure it is still correct (text may reflow due to size changes as may photo arrangement) - preview (
    Before ordering your book preview it using this method - http://support.apple.com/kb/HT1040 - and save the resulting PDF for reference - the delivered book will match it. ) and order if it is what you want
    LN

  • PDF is the wrong size from framemaker 8

    I am trying to create a PDF from Framemaker 8. The page size of the doc is US letter (216mm x 279mm)
    I am tring to change this to A4 (210mm x 297mm). Margins or extra white space is not an issue.
    Not matter what setting I change in Framemaker 8, either in the print dialog under "PDF setup" or in "Setup"
    where I am changing everything to A4 my PDF generates as 210mm x 279mm
    I have tried various job options and but still the PDF is the wrong size
    FYI I am using Frame 8/Distiller 9..
    Any ideas..?

    >Any ideas..?
    Sure, ask in http://forums.adobe.com/community/framemaker

  • Building distribution with CVI2010 always needs something from the install DVDs

    Using CVI 2010, installed from NI Dev Suite 2011 with all the defaults. When I try to build a distribution, something is always missing and must be found on the DVD.  If I don't have the DVD with me, I can't build the distribution.  It must be something simple, I know, but its not obvious what must be installed from the DVD to keep this from happening.

    If you include additional components, when you build the distribution for the first time you must insert a CD or a DVD, but as stated in the CVI help for Distribution Needed Dialog Box
    In the Distribution Not Found dialog box, enable the Cache products pulled from this distribution locally for future builds to copy all necessary components from a distribution into a permanent location on the target system. When you initiate future builds, the local system finds these components instead of prompting you to insert a distribution CD.
    Vix
    In claris non fit interpretatio
    Using LV 2013 SP1 on Win 7 64bit
    Using LV 8.2.1 on WinXP SP3
    Using CVI 2012 SP1 on Win 7 64bit, WinXP and WinXP Embedded
    Using CVI 6.0 on Win2k, WinXP and WinXP Embedded

  • Help with "You may need to enter the name and password for an administrator

    I'm trying to move files from one of my external harddrives to another external harddrive. I keep getting this message "You may need to enter the name and password for an administrator on this computer to change the item named "Documents". I also get this for other folders I want to move, but not all folders on that drive.
    I am the administrator, and it only gives me an "ok" button, no option to enter my name and password again.
    Any ideas?

    I have the same problem, trying to copy items from external hard disk to another computer on the network. I can copy without problems from external hard disk to my laptop. But not from external hard disk to another computer on the network, and neither from my laptop to another computer on the network, but ONLY if the files I try to copy from my laptop were first copied from that external hard drive. It keeps popping me up with this message. Please help, or fix.

  • Need help setting the exact size of my JSlider

    Hello everyone. I'm trying to build a small program to help people learn a about RGB colour values, and at the same time teach myself a bit more about Java. Things have been going fine so far until I came to setting my JSlider's size. The intention is to have three JSliders with a JPanel next to each. The I need the track of the slider to be exactly 256 pixels tall (one pixel per gradient value painted into the adjacent JPanel) plus whatever extra padding and spacing the Look And Feel dictates.
    I've got the height set to 256 pixels in the following code, but it makes the JSlider as a whole 256 pixels tall and so squishes the track. I've set the minor tick spacing to 2 so that if the track was actually 256 pixels tall, the ticks would alternate over each screen pixel. If you compile and run the code, you will notice that a few ticks appear next to each other without a one-pixel gap between them. I've also verified it by taking a screen capture, pasting it into the GIMP and then using the measure tool to check the size.
    I've tried searching through the API documentation to find ways of doing it, or to see if some ideas I've had so far were possible, but so far, I've not found anything particulairly satisfactory. I even tried to see if I could set the JSlider size to current JSlider size minus the track size, plus 256, but I couldn't find a way of getting the current size of the track.
    Can anyone help me out here? I'm rather stuck.

    Here's the code with all but the JSliders stripped out. Sorry about having to put it in a seperate post; the forum wouldn't allow it.
    Here's the code I have so far:
    package com.stephenphilbin.colourcoder;
    import java.awt.Color;
    import java.awt.Dimension;
    import javax.swing.GroupLayout;
    import javax.swing.GroupLayout.Alignment;
    import javax.swing.GroupLayout.ParallelGroup;
    import javax.swing.GroupLayout.SequentialGroup;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSlider;
    import javax.swing.UIManager;
    import javax.swing.border.LineBorder;
    import javax.swing.border.TitledBorder;
    public class Colourcoder extends JFrame {
        private void initComponents() {
            String colourcoderTitle = "Colourcoder";
            String lightsPanelBorderText = "Lights";
            // Create the lights panel, set the borders and set up layout references
            JPanel lightsPanel = new JPanel();
            TitledBorder lightsPanelBorder = new TitledBorder(LineBorder.createGrayLineBorder(), lightsPanelBorderText);
            lightsPanel.setBorder(lightsPanelBorder);
            GroupLayout lightsPanelLayout = new GroupLayout(lightsPanel);
            lightsPanel.setLayout(lightsPanelLayout);
            // Initialize each light slider
            JSlider[] lightSliders = new JSlider[3];
            for (int i = 0; i < lightSliders.length; i++) {
                lightSliders[i] = new JSlider(JSlider.VERTICAL, 0, 255, 0);
                lightSliders.setPaintTrack(false);
    lightSliders[i].setMajorTickSpacing(16);
    lightSliders[i].setMinorTickSpacing(2);
    lightSliders[i].setPaintTicks(true);
    lightSliders[i].setSnapToTicks(true);
    // Loop through the light sliders and add them to the lights panel
    SequentialGroup horizontalLightGroup = lightsPanelLayout.createSequentialGroup();
    for (int i = 0; i < lightSliders.length; i++) {
    horizontalLightGroup.addGroup(lightsPanelLayout.createParallelGroup().addComponent(lightSliders[i]));
    SequentialGroup verticalLightGroup = lightsPanelLayout.createSequentialGroup();
    ParallelGroup parallelLightsGroup = lightsPanelLayout.createParallelGroup();
    verticalLightGroup.addGroup(parallelLightsGroup);
    for(int i = 0; i < lightSliders.length; i++) {
    parallelLightsGroup.addComponent(lightSliders[i], 256, 256, 256);
    lightsPanelLayout.setHorizontalGroup(horizontalLightGroup);
    lightsPanelLayout.setVerticalGroup(verticalLightGroup);
    // Final window/frame configuration
    setTitle(colourcoderTitle);
    setResizable(false);
    setLocationRelativeTo(null);
    GroupLayout frameLayout = new GroupLayout(getContentPane());
    getContentPane().setLayout(frameLayout);
    frameLayout.setAutoCreateContainerGaps(true);
    frameLayout.setHorizontalGroup(
    frameLayout.createParallelGroup(Alignment.LEADING)
    .addGroup(
    frameLayout.createSequentialGroup()
    .addComponent(lightsPanel))
    frameLayout.setVerticalGroup(
    frameLayout.createParallelGroup(Alignment.LEADING)
    .addGroup(
    frameLayout.createSequentialGroup()
    .addComponent(lightsPanel))
    pack();
    public Colourcoder() {
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    UIManager.put("swing.boldMetal", Boolean.FALSE);
    try {
    UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    } catch (Exception ex) {
    System.exit(1);
    initComponents();
    * @param args the command line arguments
    public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Colourcoder().setVisible(true);
    Edited by: S_Philbin on Sep 29, 2008 11:18 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Need to reduce the report size.

    Hi all,
    I am using CR2008, i have total 4 images(jpeg) in the header and footer. My problem is  size of the rpt file. i am getting 8MB for the blank report itself. so i cant able to export this file properly from my  application(.net)into .doc and RTF formats if the report having more than 20 pages. When i remove the whole images from the rpt the size is getting down to around 150KB.
        The DPI of the Image is 600 with same height and diffrent width.but the total image size is only 160Kb.i cant able to compromise the resolution of the image. While i am reducing the DPI, the size of the rpt is also decreasing. How can i overcome this problem without reducing the image resolution.
    Hope anyone will give the solution for this,
    Thanks in Advance,
    Salah.

    I ran into the same issue and was able solve the problem.
    When you insert a jpeg into a report, the jpeg is converted to a  bitmap so  for example a 200K jpg file can explode to 3 megs.
    I was able to solve the problem by opening my bitmap(which was black and white) in photoshop and converting the  bitmap to grayscale. Then when saving the converted bitmap I compressed the file.
    Then I inserted the image into the report as a OLE object which keep the new size of the file.
    Then the other thing you need to do is make sure you have Retain Original Color Depth check on under your report options so that the image will retain it resolution.

  • I need  to adjust the screen size but i cannot find where at

    Can anyone help me out, i am done with my video but i realize too late that the screen size is really weird, large and not tall at all

    Sorry, I can't translate since your title is in English and the translator won't apparently do the rest. I am guessing in my answer. Adobe used to have the Distiller Server, but I think that has been discontinued. Distiller normally comes as part of Acrobat. To install Distiller, you would simply install Acrobat. If you have Acrobat installed and for some reason Distiller is not showing up, try opening Acrobat and go to Help>Repair. It is a good idea to do the updates also.
    If you need more info, please give the software version that you have and name, along with the OS. Also it appears you may have to post in English since the translator will not work. You might create a version in your language and use https://translate.google.com/ to translate and copy to the forum.

Maybe you are looking for

  • What do I do if the screen turned black with red line across it and it wont resod?

    I have tryed everything i could think of but it still wont wotk!!!!!!!!!!!

  • Wireless issues when plugging into Mac display

    I have noticed that no matter where I am in the house, my Macbook Pro works with my Airport just fine. But when I plug the laptop into a 24" display, my wireless signal does one of two things: it drops a connection, going from full strength to nothin

  • Get the flv total time in AS2

    Hi. I am loading a flv video in AS2: var conexion:NetConnection = new NetConnection(); conexion.connect(null); var stream:NetStream = new NetStream(conexion); mi_video.attachVideo(stream); stream.play("motto.flv"); this.onEnterFrame = function() {   

  • JMS - Oracle - ArchieveLog

    Welcome,           Digital World!!!           Everything is limited, even "random" produces periodic sequence...           Is here any advice to Senior Oracle DBAs not to use ArchiveLog for JMS           Schema?           Today, I had 2500msg/min., e

  • Best practices for implementing OIM

    We plan on putting OIM servers behind LB (hardware). When I develop OIM client I am required to specify OIM endpoint(s) via property java.naming.provider.url. In case of LB I'd specify a virtual host there. The question is what is the best practice f