Thanks for all the replies.
This suggestion worked.
I actually thought from GridBagLayouts' flexibility that it was easier even
though it required more lines of code.
Ive learned the hard way that SWING programming in itself is not all that
intuitive.
Thanks again for your help.

-----Original Message-----
From: Song, Mingjian [mailto:[EMAIL PROTECTED]
Sent: Monday, December 29, 2003 4:27 PM
To: Gregory, Carlton; [EMAIL PROTECTED]
Subject: RE: JScrollPane does not appear


Hi,

Try to use BorderLayout to layout the stuff in the installContentPane.
The code I have here may not be the exact layout you want, but at least
it does not shrink the scroll pane.


Remove this line:
logScrollPane.setPreferredSize(new Dimension(70,50));

Remove these:
        gbc.gridy = 3;
        gbc.gridwidth = 2;
        gbc.gridheight = 4;
        fcPanel.add(logScrollPane,gbc);

Change the layout of installContentPane at the end of the "startInstall" 
method to:

        //fcPanel.setMinimumSize(PaneDim);
        fcPanel.setPreferredSize(PaneDim);
        installContentPane.setPreferredSize(PaneDim);
        installContentPane.setLayout(new BorderLayout()); // added
        installContentPane.add(fcPanel, BorderLayout.NORTH); // changed
        installContentPane.add(logScrollPane, BorderLayout.CENTER); // added
        installerFrame.setSize(600,300);
        logScrollPane.revalidate();

GridBagLayout is not easy to use, although it is flexible. Just in case 
you do not know, here are some good tutorials about layout mangers.
http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html
http://manning.com/sbe/files/uts2/Chapter4html/Chapter4.htm

Hope that helps.


Mingjian Song


-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Behalf Of
Gregory, Carlton
Sent: Monday, December 29, 2003 12:59 PM
To: '[EMAIL PROTECTED]'
Subject: RE: JScrollPane does not appear


I changed some code now my JScrollPane appears but it is very small.

This occurs even after setting the size. Any suggestions?

/*
 * Copyright �.
 */


import java.io.*;
import java.util.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.*;

/**
 * @author  cgregory
 */
public class SamsInstaller //implements Observer
{
    JButton okbutton;
    JButton cnbutton;
    JButton openButton;
    JButton closebutton;
    JFrame installerFrame;
    JPanel installPanel;
    JPanel installContentPane;
    JPanel fcPanel;
    JPanel fcButtonPanel;
    JPanel buttonPanel;
    JPanel instrPanel;
    JTextArea log;
    JTextArea instructions;
    JFileChooser fc;
    
        public SamsInstaller()
        {
        installerFrame = new JFrame("SAMS9 DIICOE Installer");
        installContentPane = new JPanel();
        installPanel = new JPanel();
        okbutton = new JButton("START");
        cnbutton = new JButton("EXIT");
        
        JLabel introLabel = new JLabel("SAMS9 Database Installation \n" +
                                       "Space and Naval Warfare Systems
Center Norfolk \n" +
                                       "           (SPAWARSYSCEN)
");
        
        okbutton.addActionListener(new InstallListener());
        cnbutton.addActionListener(new InstallListener());
        installerFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        installPanel.setLayout(new GridBagLayout());
        GridBagConstraints BagConstrnts = new GridBagConstraints();
        buttonPanel = new JPanel();
        buttonPanel.add(okbutton);
        buttonPanel.add(cnbutton);
        /*
        installPanel.setBorder(BorderFactory.createCompoundBorder(
        BorderFactory.createTitledBorder("SAMS9 DIICOE Installation"),
        BorderFactory.createEmptyBorder(10,10,10,10)));
        */
        installPanel.setBorder(BorderFactory.createRaisedBevelBorder());
        
        Insets myinset = new Insets(0,0,0,0);
        BagConstrnts.anchor = BagConstrnts.CENTER;
        BagConstrnts.insets = new Insets(0,10,0,0);
        BagConstrnts.gridx = 0;
        BagConstrnts.gridy = 0;
        BagConstrnts.gridwidth = 2;
        BagConstrnts.ipady = 40;        
        installPanel.add(introLabel,BagConstrnts);
        
        BagConstrnts.gridx = 0;
        BagConstrnts.gridy = 4;
        BagConstrnts.ipady = 0;
        BagConstrnts.gridwidth = 0; 
        installPanel.add(buttonPanel,BagConstrnts);
        
        installContentPane.setOpaque(true);
        installContentPane.add(installPanel);
        
        installerFrame.setContentPane(installContentPane);
        installerFrame.setSize(800,300);
        installerFrame.setVisible(true);
        }
        //public void update(Observable o, Object str) 
    //{
    //}
    public void startInstall()
    {
        //Create the log first, because the action listeners
        //need to refer to it.
        log = new JTextArea(5,20);
        log.setMargin(new Insets(5,5,5,5));
        log.setEditable(false);
        log.append("This is a test");
        JScrollPane logScrollPane = new JScrollPane(log);
        logScrollPane.setPreferredSize(new Dimension(70,50));
        //Place instructions of what to do 
        instructions = new JTextArea("Please select the directory were your
Oracle " +
                             "For example
\"C:\\oracle\\oradata\\samsdb\"",5,30);
        instructions.setBackground(Color.lightGray);
        instructions.setLineWrap(true);
        JPanel instrPanel = new JPanel();
        
        //Create a Label that will be invisible to create space
        //JLabel invisibleLabel = new JLabel();
        //invisibleLabel.setVisible(false);
        //Create a file chooser
        fc = new JFileChooser();
        fc.setDialogTitle("Select Data Directory");
     
        //Uncomment one of the following lines to try a different
        //file selection mode.  The first allows just directories
        //to be selected (and, at least in the Java look and feel,
        //shown).  The second allows both files and directories
        //to be selected.  If you leave these lines commented out,
        //then the default mode (FILES_ONLY) will be used.
        //
        fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
        //fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

        //Create the open button.  We use the image from the JLF
        //Graphics Repository (but we extracted it from the jar).
        openButton = new JButton("Select a Directory");
        openButton.addActionListener(new FileChooseLisnr());
        fcPanel = new JPanel(new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        
        fcButtonPanel = new JPanel();
                
        
        
        Dimension PaneDim = new Dimension(700,150);
        instrPanel.add(instructions);
        gbc.gridx = 0;
        gbc.gridy = 0;
        gbc.anchor = gbc.FIRST_LINE_START;
        fcPanel.add(instrPanel, gbc);
        gbc.gridx = 0;
        gbc.gridy = 1;
        gbc.anchor = gbc.CENTER;
        fcPanel.add(openButton,gbc);
        gbc.gridy = 3;
        gbc.gridwidth = 2;
        gbc.gridheight = 4;
        fcPanel.add(logScrollPane,gbc);
        
        //fcPanel.setMinimumSize(PaneDim);
        fcPanel.setPreferredSize(PaneDim);
        installContentPane.setPreferredSize(PaneDim);
        installContentPane.add(fcPanel);
        installerFrame.setSize(600,300);
        logScrollPane.revalidate();
    }
        public static void main(String[] args)
        {
       
       
        SamsInstaller installerInstance = new SamsInstaller();
        

       
        }
    class FileChooseLisnr implements ActionListener {
        
        public void actionPerformed(ActionEvent event) {
          
           if (event.getSource() == openButton)
           {
           int returnVal = fc.showDialog(fcPanel, "Set Data Dir");
               if (returnVal == JFileChooser.APPROVE_OPTION)
               {
                System.out.println(fc.getSelectedFile());
               }
           } 
        }
              
     }
    class InstallListener implements ActionListener {
        
        public void actionPerformed(ActionEvent event) {
          
           if (event.getSource().equals(cnbutton))
          {
            System.exit(0);
          }
          else
          {
            installPanel.setVisible(false);
            startInstall();
            
           }
           
        }
              
     }
        
}
_______________________________________________
Swing mailing list
[EMAIL PROTECTED]
http://eos.dk/mailman/listinfo/swing

Reply via email to