Changeset 1800


Ignore:
Timestamp:
11/16/06 14:11:42 (14 years ago)
Author:
curtis
Message:

Fix scroll bar issue with GenericDialogs.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/loci/plugins/Importer.java

    r1798 r1800  
    259259          sd.addCheckbox(seriesStrings[i], series[i]); 
    260260        } 
    261 //        addScrollBars(sd); 
     261        addScrollBars(sd); 
    262262        sd.showDialog(); 
    263263        if (sd.wasCanceled()) { 
     
    287287            rd.addNumericField("Step" + s, step[i], 0); 
    288288          } 
    289 //          addScrollBars(rd); 
     289          addScrollBars(rd); 
    290290          rd.showDialog(); 
    291291          if (rd.wasCanceled()) { 
     
    695695 
    696696  private void addScrollBars(Container pane) { 
    697     LayoutManager layout = pane.getLayout(); 
     697    GridBagLayout layout = (GridBagLayout) pane.getLayout(); 
     698 
     699    // extract components 
    698700    int count = pane.getComponentCount(); 
    699701    Component[] c = new Component[count]; 
    700     for (int i=0; i<count; i++) c[i] = pane.getComponent(i); 
     702    GridBagConstraints[] gbc = new GridBagConstraints[count]; 
     703    for (int i=0; i<count; i++) { 
     704      c[i] = pane.getComponent(i); 
     705      gbc[i] = layout.getConstraints(c[i]); 
     706    } 
     707 
     708    // clear components 
    701709    pane.removeAll(); 
    702     pane.setLayout(new BorderLayout()); 
    703  
     710    layout.invalidateLayout(pane); 
     711 
     712    // create new container panel 
    704713    Panel newPane = new Panel(); 
    705     newPane.setLayout(layout); 
    706     for (int i=0; i<count; i++) newPane.add(c[i]); 
     714    GridBagLayout newLayout = new GridBagLayout(); 
     715    newPane.setLayout(newLayout); 
     716    for (int i=0; i<count; i++) { 
     717      newLayout.setConstraints(c[i], gbc[i]); 
     718      newPane.add(c[i]); 
     719    } 
     720 
     721    // get preferred size for container panel 
     722    // NB: don't know a better way: 
     723    // - newPane.getPreferredSize() doesn't work 
     724    // - newLayout.preferredLayoutSize(newPane) doesn't work 
     725    Frame f = new Frame(); 
     726    f.setLayout(new BorderLayout()); 
     727    f.add(newPane, BorderLayout.CENTER); 
     728    f.pack(); 
     729    Dimension size = newPane.getSize(); 
     730    f.remove(newPane); 
     731    f.dispose(); 
     732 
     733    // compute best size for scrollable viewport 
     734    size.width += 15; 
     735    size.height += 15; 
     736    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); 
     737    int maxWidth = 3 * screen.width / 4; 
     738    int maxHeight = 3 * screen.height / 4; 
     739    if (size.width > maxWidth) size.width = maxWidth; 
     740    if (size.height > maxHeight) size.height = maxHeight; 
     741 
     742    // create scroll pane 
    707743    ScrollPane scroll = new ScrollPane(); 
     744    scroll.setPreferredSize(size); 
    708745    scroll.add(newPane); 
    709     pane.add(scroll, BorderLayout.CENTER); 
     746 
     747    // add scroll pane to original container 
     748    GridBagConstraints constraints = new GridBagConstraints(); 
     749    constraints.fill = GridBagConstraints.BOTH; 
     750    constraints.weightx = 1.0; 
     751    constraints.weighty = 1.0; 
     752    layout.setConstraints(scroll, constraints); 
     753    pane.add(scroll); 
    710754  } 
    711755 
Note: See TracChangeset for help on using the changeset viewer.