JScrollPane viewport size question

Hi all,
I've a component that is very large (it has a dinamic height) but its width is always the same (fixed). I need to show this component in a JScrollPane container and only shows the vertical scrollbar. It works fine but when my applications runs, the component inside the JScrollPane (yes..my component) get a different width, which is larger than the original componet's width
I'm using the following code:
        JScrollPane scroll = new JScrollPane(myComponent);
        scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);My question is, How I can do for set a fixed width to the JScrollPane (its viewport or its child component) in order to get the correct component width and only allows a dinamic height ?
thanks in advance

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.Random;
public class Test3 extends JFrame {
  JPanel jp = new JPanel();
  JScrollPane jsp = new JScrollPane(jp);
  JLabel jl = new JLabel("", JLabel.CENTER);
  Random rand = new Random();
  public Test3(){
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    Container content = getContentPane();
    content.add(jl, BorderLayout.NORTH);
    jp.setBorder(BorderFactory.createLineBorder(Color.blue));
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    jsp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    content.add(jsp, BorderLayout.CENTER);
    JButton jb = new JButton("Random Height");
    content.add(jb, BorderLayout.SOUTH);
    jb.addActionListener(new ActionListener() {
      public void actionPerformed(ActionEvent ae) {
        int height = rand.nextInt(1000);
        jp.setPreferredSize(new Dimension(jsp.getViewport().getWidth(),height));
        jsp.getViewport().revalidate();
        jl.setText(""+height);
    setSize(300,300);
  public static void main(String[] args) {new Test3().setVisible(true); }
}

Similar Messages

  • Is there a maximum viewport size for an EPUB file in iBooks?

    I have noticed that very large viewports sometimes cause iBooks to crash. Is there a maximum size allowed?
    thanks,
    Liz

    The viewport size I use is 512px wide by 768px high for my individual .xhtml pages.  For a two-page spread this would mean the viewport is actually 1024px by 768px.
    Yet I paint my original images for a Children's Read Aloud Fixed Layout ePub at 2048px wide by 1536px high and then cut the painting in half for a two page spread.  This means on the new retina display, my images will look great yet be backward compatible with the original iPad.

  • IMovie 6 HD - Export Movie Size Question

    There is a confusing list of movie export size options that I need to get your clarification about. Some of the selections seem to be similar.
    To see what I am referring to go into iMovie HD 6, under the SHARE menu, go to Save Movie For: Expert Settings Export Settings > Select Movie to QuickTime Movie (then hit the options tab to the right > Under the Video Section, select SIZE - note the Export Size Settings - DImensions drop down list. Note there are two sections. The last two items in the top section listed are (exactly worded as) 1280 x 720 HD and 1920 X 1080 HD. In the bottom section the last three entries are HD 1280 x 720 16:9, HD 1440 x 1080 16:9 and HD 1920 x 1080 16:9. What's the difference, for example, between the 1280 x 780 HD and the bottom one HD 1280 x 780 16:9? I ask because my HD camcorder movie footage (shot at 1080i, 29.97, 16:9) with an HV30 exports smooth at 1280x720 HD but jerky at HD 1280 x 780 16:9. They sound the same, but one is jerky and one smooth.
    The other question I have is 1440x1040 is 4:3 ratio. But it exports at 16:9 aspect ratio. I don't understand why.

    Donna:
    While I have a lot of video editing experience with an SD digital camcorder, the Canon HV30 HDV cam is new to me. So I am experimenting. That said, footage that will be shot will end up in a couple of places. Some of it will be passed onto my company's web master for posting to the web in some kind of Flash video format. Other video will be used in Keynote presentations as full screen video clips. Others will be used as source video for creating 4x3 SD clips for PowerPoint on a PC by others. So, the video will be used in different formats. (In what format to shoot is another question, but I have concluded (I hope correctly) that I should just shoot HDV 1080i since it seems to be the easiest to deal with for uploading to iMovie6 HD.)
    The purpose of my inquiry was to determine what the various selections are used for and what they do. Sometimes the video is jerky, sometimes an identical movie size is smooth (but must be rendered or processed differently). I was only trying to determine why there appeared to be repetative choices in the list of movie sizes as I mentioned in my original post. To be blunt, iMovie 6 HD documentation is spotty at best. The O"Reilly books don't cover the hard parts.

  • IMac (24-inch, Early 2009) Hard Drive Replacement: Hybrid and Maximum Size Question

    I have a 24-inch iMac, early 2009 model and the internal hard drive has died so am looking to replace it and also upgrade it in the process.
    At the moment the broken internal drive was the standard 1TB model that comes with the computer. I have been doing a little bit of research and I'm liking the sound of a hybrid drive as they seem to be a relatively economical was of achieving close to SSD speeds. I've been looking particularly at 'Seagate ST4000DX001 DESKTOP SSHD 4TB SATA 6GB/s NCQ NAND 8GB 64MB HYBRID' for the replacement. I guess my question is if this drive will work in the iMac. Does a hybrid drive present and problems? Also, is there a limit to the maximum size the replacement drive can be? Will 4TB exceed this limit? Lastly, I understand this drive uses SATA III to connect with the computer, which is backwards compatible (I think?) so I'm presuming this will work in my iMac?
    Thanks in advance.

    The hybrid drive will kinda sorta be as fast as an SSD. The newest Seagate Hybrid is quite intelligent about caching the most often used files in flash and is quite an improvement over the first iteration. I used both the first and second generation drives in my 2007 iMac and was quite impressed with their performance…until I installed an SSD. The problem with the hybrids is that they just don’t have enough flash and no matter how intelligent the drive is it is guesswork so sometimes you’ll find the drive access just as pokey as any other 5400 RPM drive and then other times very fast.
    For about $200 it is a decent upgrade but with SSD prices having dropped nearly 50% in the last 18 months it is worth considering a smallish internal SSD for the OS and applications and an external drive for data.

  • JTable in JScrollPane, preferred size

    When I put a JTable in a JScrollPane, the JScrollPane seems to want to be very big. How does the scroll pane determine its size? run this code for an example..
    import javax.swing.*;
    public class TestPanel extends JPanel
    public TestPanel()
         add(new JScrollPane(new JTable(1,1)));
    public static void main(String args[])
         JFrame f = new JFrame("big table test");
         f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         TestPanel thePanel = new TestPanel();
         f.setContentPane(thePanel);
         f.pack();
         f.show();

    public class TestPanel extends JPanel {
      public TestPanel() {
        JTable jt = new JTable(1,1);
        jt.setPreferredScrollableViewportSize(new Dimension(100,100));  // Do this
        JScrollPane jsp = new JScrollPane(jt);
        jsp.setPreferredSize(new Dimension(100,100));  //OR this
        add(new JScrollPane(new JTable(1,1)));
    }

  • File size questions

    new to Apple MAC and iPhoto...so....I shot my new camera in jpeg, files are roughly 20mb...then I shot in RAW and after editing, the saved jpegs are ~ 5-10mb and up to 15mb....what happens to make this discrepency? how could my RAW converted jpegs be ~ 1/3 the size of straight out of camera jpegs?
    another question...iPhoto is 1.7 gb, my iPhoto Library size it 37gb, but my pictures in iPhoto total 17gb.....is the discrepecy due to stuff like Slideshows I created? Faces just is referring the files right, not making duplicate files?...having trouble wrappping my head around stuff I''m seeing that doesn't add up...
    thanks

    It's all a bit more complex that that. There is no correlation between file size and the quality of a shot. A well exposed shot of 2 or 3 mb will print just as well as a well exposed shot of 25mb. There is no difference in what gets printed. A poorly exposed shot of 25mb will print like garbage.
    It gets worse, we used to suggest a rule of thumb that printing at 300dpi was a reasonable giude to printing quality. Not any more. Printers and cameras have improved, iPhoto books are uploaded at something akin to 150 dpi.
    Again, a 3 mb jpeg will print exactly as well as a 30 mb tiff.
    Remember, the internet is full of high quality images that weigh in at a lot less than 500kb.
    Where file size comes into play is when you're using destructive editing on a lossy format, like Jpeg, and, as I said above, that doesn't come into play in a non-destructive editing system like iPhoto.
    The output from the export will - depending on the settings you use - either be smaller or larger than the jepg from a camera. It means very little - unless you're going to go an an edited destructively.

  • JScrollPane + Component sizes before display

    I was recently presented with a minor quandry.
    I have a JPanel which needs to occupy a minimum fixed amount of real estate on my application's GUI, call it 'checkbox_jpanel'. The problem is that as the user operates the application, more and more checkboxes will be added to it. This works fine until I reach the size limit of the JPanel.
    The obvious solution seemed to be to use a JScrollPane, and simply tuck the checkbox_jpanel inside of it. That way, I could dynamically resize the JPanel, and the JScrollPane could take care of displaying it.
    Simple, until I realized that there's no good way to ask a layout manager how much space it had planned to let a given component take up, including buffer pixels. I can't even ask the component itself because, having not yet been drawn, it doesn't know how big it is either.
    Currently, I'm able to get this strategy to work by guessing - eyeballing the number of pixels + space - each new checkbox takes up for the height * the number of items, and the width is based on the largest constant + (constant-intended-to-represent-average-character-width*letters in text portion of checkbox) among the set of checkboxes. I use that width and height to set the preferredSize of the JPanel i'm actually adding to.
    I wince when I look at that code.
    The comment above it says "This really needs to be done correctly."
    How could I do this 'correctly' ?
    The only thing I've been able to come up with is almost as ugly; make the checkbox_jpanel some insanely large size that will always encompass EVERYTHING, insuring that the checkboxes will be drawn, force/wait for the redraw, and then recalculate the width/height, and reset the panel to the desired (correct) width and height. I don't know if I could get this done without a bit of flickering, and really, everything about it screams 'non-optimal solution'.
    Any thoughts?

    Just an idea: the sizes become calculated when the components become visible OR when the application frame is packed... perhaps you could use a call to pack(), then do your job, then finally show your frame ?

  • Oracle Block Size - question for experts

    Hi ,
    For years i thought that my system block size was 8K.
    Lately due to an HPUX Bug i found that the file system block size is gust .... 1K
    (HP DocId: DCLKBRC00006913 fstyp(1m) returns unexpected block size (f_bsize) for VXFS )
    My instance is currently 10204 but previously was 7.3 --> 8 --> 8174 --> 10204.
    Since its old instance its block size is gust 4kb.
    We are planing to create new file system block size of 8k.
    The instance size is about 2 TB.
    Creating the whole database with 8 kb is impossible since its 24*7 instance.
    Do you think that i sould move gust few important tables to a new tablespace with 8k block size , or should i leave it with 4 kb ?
    Thanks

    Given that your Oracle Database Block_Size (4K) is a multiple of the FileSystem Block_Size (1K), there should be no inherent significant issue, as such.
    Yes, it would have been nice to have an 8KB Oracle Database Block_Size but whether you should recreate your FileSystems to 8KB is a difficult question. There would be implications on PreFetch that the OS does and on how the underlying Storage (must be a SAN, I presume) handles those requests.
    A thorough test (if you can setup a test environment for 2TB such that it does NOT share the same HW, doesn't complicate PreFetches in the existing SAN) would be well adviced.
    Else, check with HP and Veritas support if there are known issues and/or any Desupport plans for this combination ?!
    Oracle, obviously, would have issues with Index Key Length sizes if the Block Size is 4KB. Presumably you do not need to add any new indexes with very large keys.
    Having said that, you would have read all those posts about how Oracle doesn't (or really does ?) test every different block-size ! However, Oracle had, before 8i, been using 2K and 4K block sizes. Except that the new features (LMT, ASSM etc) may not have been well tested.
    Since you upgraded from 7.3 in place without changing the Block_Size, I would venture to say that your database is still using Dictionary Managed and Manual Allocation and Segment Space Management Manual ?
    Hemant K Chitale
    http://hemantoracledba.blogspot.com

  • Player size question for player developers

    Question for all player developers:
    For media players that you've built or that you've seen out on the web today, how big are they in k?  And of that total size, how much code does it take to support each of the service integrations with CDNs, ad servers/networks, analytics services, and content management systems? 
    I'm interested in total player size, the % of that total devoted to each type of service integration, and the average for an individual service integration.
    -Sumner

    As I understand it, the new FME (Jan 2008?) will include
    support for mp3 audio and much higher audio bitrates, as well as
    possibly DRM.

  • Canon sRAW to DNG Size Question

    Hi,
    I shot some images with my Canon 40D set to sRAW. A sample image size is 6.1 MB. In Lightroom 1.3.1, I convert the RAW (.CR2) file to DNG. The resulting DNG file is 6.7MB in size. The DNG Creation settings I used in the conversion were:
    JPEG preview: None
    Image Conversion Method: Preserve Raw Image
    Options: Compressed - ON / Embed Original Raw File - OFF
    I was under the impression that DNG format would be smaller than the RAW format.
    Is this larger DNG file because my original RAW file was a compressed RAW file (sRAW) and, as a result, the RAW image needs to be uncompressed before it is converted into a DNG file? If the original RAW image was NOT compressed, would I be seeing a reduction if file size after the DNG conversion.
    I guess the heart of my questions is this: Will conversion from RAW to DNG only provide a file size reduction if the original RAW file is uncompressed? Is it normal for me to see an increase in size when converting from sRAW to DNG, due to the fact that the original RAW file is a compressed RAW format?
    Thanks in advance for your clarification.
    Steve

    The reason for the larger DNG file is quite complicated, one needs to know some JPEG details. In short, the original sRaw file contains four 15 bit pixel values for two pixels, while the DNG file contains three values per pixel.
    The size difference would be much larger if the CR2 file did not contain a 050 KB large thumbnail, which is in the DNG file only between 100 KB abd 200 KB large (approximation).
    Plus, the DNG converter fine-tunes the compression; this is not affordable in-camera.

  • JPEG - Original Size question

    Hi gang,
    Strange question.
    I accidentally edited my Export .. Versions ... JPEG Original Size settings. Can someone let me know the original settings?
    Cheers!

    H there,
    "Original Size" picks up the resolution from the image, so is image dependent.
    The DPI settings by default are 300.
    G.

  • Site Size Question? How many Pixels?

    Hi, you can view my site here:
    http://www.recordingnyc.com
    My question is: My site is 800 Pixels wide. I think I read
    somewhere ages ago that if you don't have a site that's 100% width,
    you should keep the size to 800px. Is this true....or should I say
    is this true anymore? I would like my site to be, let's say 950px
    wide. Would that not be a good idea for technical reasons?
    Also, feel free to critique my site. After 20 years of not
    advertising my services, I finally decided to bite the bullet and
    build one. Please let me know what you think and how I could
    improve it?
    Thank you very much for any help!

    engmix wrote:
    > Hi, you can view my site here:
    http://www.recordingnyc.com
    >
    > My question is: My site is 800 Pixels wide. I think I
    read somewhere ages ago
    > that if you don't have a site that's 100% width, you
    should keep the size to
    > 800px. Is this true....or should I say is this true
    anymore? I would like my
    > site to be, let's say 950px wide. Would that not be a
    good idea for technical
    > reasons?
    You pays your money you takes your choice to be honest.
    Nothing can be
    considered to cover everything and every ones screen/browser
    set ups.
    The higher the screen resolution the more the end user can
    accommodate a
    wider design in their browser window (the browser window
    being set at
    what physical size, in proportion to the screen, they think
    is
    'comfortable').
    If you change your pages width from 800px to 950px at the
    current screen
    resolution that my computer is set up at it will show
    horizontal
    scrollbars. If I alter my screen resolution to be higher than
    it
    currently is I can then open the browser widow wider and your
    page will
    most likely be ok at 950px width.
    If you leave your page width at 800px wide and I still alter
    my screen
    resolution to higher than it currently is your page looks as
    though it
    should be wider i.e., you have excess amounts of black real
    estate on
    both the left and right. If the page is set left and not
    centered this
    obviously compounds the problem.
    The answer is YOU CANNOT design for everyones computer set up
    unless you
    use a fluid page width i.e. set it at 100%.
    I would stay at around 750px - 800px so you can take
    advantage of more
    users. The facts (if they are to be believed) reveal there
    are more
    people still using lower resolution set ups than those that
    are using
    higher ones.
    > Also, feel free to critique my site. After 20 years of
    not advertising my
    > services, I finally decided to bite the bullet and build
    one. Please let me
    > know what you think and how I could improve it?
    On the up side your site is clean and user friendly but lacks
    any visual
    stimulant for my tastes.
    Personally I think its too boxy and looks detached rather
    than being one
    entity.
    Ulitmately there is nothing wrong with it but its just
    lacking a little
    bit of 'magic dust' of some kind.
    I wouldn't take the critic too much to heart, I just feel it
    could
    somehow hang together a little better and make me want to
    take a look
    around a bit more than I do.
    Obviously if youre not from a design background then its a
    mighty good
    effort. If you are then you should be able to do a little
    better.

  • JLists, JScrollPanes different size when empty than when populate

    I have a JList which is inside of a JScrollpane, which is inside of a panel who's layout is controlled with a GridBagLayout.
    When I first start my program, and the JList is empty, the JList is the size I want. The GridBagLayout is set to fill both directions for the JList.
    However, when I add an item to the JList, the GridBagLayout resizes the cell that the JList is inside of just slightly. How can I prevent this? It is obnoxious to use the program when the all the items on the screen change size a little bit when a JList goes empty as opposed to when it is populate.
    Why does a JList (inside of a scrollpane) get a different size assigned to it by the grid bag layout when it is empty, as to when it has items in it?

    Setting the preferred size on the scroll pane containing the list corrects 1/2 of my problem - The vertical space alloted by the grid bag layout no longer changes with an empty list compared to a populated list.
    I'll give the first guy a couple of points.
    The rest of the points are still up for grabs ----
    I still have problems with side by side lists which have items that can be moved back and forth.
    I tried setting min size and preferred size on the scroll panes.
    I tried putting each scroll pane into its own JPanel that had a Grid Layout, and then added the panels to my main panel with a grid bag layout, and weights set to .5 for horizontal expansion.
    I even tried putting min, preferred, and max sizes on these panels.
    I still cannot make the grid bag layout alot equal space to the left and right scroll panes.
    Is there any way that I can get the space alloted between my components to be roughly
    ====================
    || 45% || 5% || 45% ||
    || JList || buttons || JList ||
    ====================
    Ane then have only the outside two columns change size when the window is resized (in equal proportion)???

  • MSI P6N SLI Platinum Voltage regulator cooler size question

    I have a question about MSI P6N SLI Platinum's Voltage regulator cooler. Is it the same size of K9N SLI Platinum? The reason I ask is I plan to use water cooling on it. But the only regulator  waterblock I can find is desgined for K9N SLI Platinum from aqua computer http://www.aqua-pcs.co.uk/index.asp?function=DISPLAYPRODUCT&productid=218. So can I use this one on P6N SLI?

    I guess not... P6N is much thinner, if your K9N VR cooler is as thin, then it can fit in. But I guess not.

  • Custom Page Size Question

    If I choose one of the fly-out "edit page size options" at the bottom of the pages palette, such as compact disc or business card, why does the page size still say 8.1/2 x 11 if I go to--> "document set-up"? Is there a way that you can tell the actual size of the card or disc short of drawing a text or pic box? Also- if I have a document that is supposed to be several 8.1/2 x11 pages, and one page is set up at 7x11. Is there a way to find that out w/o weeding thru the entire doc? I cant find anything in Preflight that clues you in on that. Thanks for any input on this.

    When first added, I thought multiple page sizes would be a great addition for doing things like book jackets (for easily adjusting the spine) and Letterhead, Envelope and Business Card packages (for easy organization) but after seeing it in action I've pretty much decided there is no particular advantage, and quite a few drawbacks, in a print output workflow. It makes more sense, perhaps, in a workflow intended for mobile devices, paricularly something that needs two orientations of the same page for those who want to rotate their tablet screen, and I suspect it was envisioned as part of the apparent push to move ID into the new realm of digital publishing.

Maybe you are looking for