Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

gridBagLayout and scrollbars

$
0
0
Hello,

I took the advise of a resident pro on here and am learning about layouts.

I am using Internal frames to write a program and gridBagLayout to design my pages within the internalframe.

The problem comes from how do I add vertical and horizontal scroll bars on the InternalFrame??

I searched around and I cannot sem to find how to add it right to the internal frame itself? All I could find is how to attach it to text areas inside the IFrame??

any help would be appreciated

Below is the code I am using to build the gridBagLayout in case this helps:

    public Container start(Container pane) {
        
        if (RIGHT_TO_LEFT) {
            pane.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
        }
        
     pane.setBackground(Color.LIGHT_GRAY);

	pane.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	if (shouldFill) {
	//natural height, maximum width
	c.fill = GridBagConstraints.HORIZONTAL;
	}
        
        //header for login
	JLabel Head = new JLabel("Log in");
	c.weightx = 0.5;
	c.fill = GridBagConstraints.CENTER;
        c.gridwidth = 2;
	c.gridx = 0;
	c.gridy = 0;
        c.ipady = 40;
	pane.add(Head, c);

        //username label
	JLabel UNText = new JLabel("UserName:");
	c.fill = GridBagConstraints.EAST;
        c.gridwidth = 1;
	c.gridx = 0;
	c.gridy = 1;
        c.ipady = 5;
	pane.add(UNText, c);
        
        //username field
	UN = new JTextField(10);
	c.fill = GridBagConstraints.WEST;
	c.ipady = 5; 
	c.gridwidth = 1;
	c.gridx = 1;
	c.gridy = 1;
	pane.add(UN, c);
        
        //password label
	JLabel PWText = new JLabel("PassWord:");
	c.fill = GridBagConstraints.EAST;
        c.gridwidth = 1;
	c.gridx = 0;
	c.gridy = 2;
        c.ipady = 5;
	pane.add(PWText, c);
        
        //password field
	PW = new JPasswordField(10);
	c.fill = GridBagConstraints.WEST;
	c.ipady = 5; 
	c.gridwidth = 1;
	c.gridx = 1;
	c.gridy = 2;
	pane.add(PW, c);        

        //login button
	JButton Login = new JButton("LogIn");
	c.fill = GridBagConstraints.CENTER;
	c.ipady = 0;       //reset to default
	c.weighty = 1.0;   //request any extra vertical space
	//c.insets = new Insets(1,0,0,0);  //top padding
	c.gridx = 0;       //aligned with button 2
	c.gridwidth = 2;   //2 columns wide
	c.gridy = 3;
        Login.addActionListener(new ActionListener() {
                
            @Override
            public void actionPerformed(ActionEvent e) {
                
                try {
                    login();
                } catch (PropertyVetoException ex) {
                    Logger.getLogger(LoginGUI.class.getName()).log(Level.SEVERE, null, ex);
                }

            }                
                
        });
	pane.add(Login, c);
        
        //error reporting to user
	Error = new JLabel("");
        Error.setForeground(Color.RED);
	c.weightx = 0.5;
	c.fill = GridBagConstraints.CENTER;
        c.gridwidth = 2;
	c.gridx = 0;
	c.gridy = 4;
        c.ipady = 10;
	pane.add(Error, c);        
        
        return pane;
        
    }



and this is where I am building the Iframe:

public class InternalFrame extends JInternalFrame {
    static int openFrameCount = 0;
    static final int xOffset = 30, yOffset = 30;
    String Name;

    public InternalFrame(String name, String namelook, Boolean resize, Boolean closable, Boolean max, Boolean icon) {
        super(namelook,
              resize, //resizable
              closable, //closable
              max, //maximizable
              icon);//iconifiable
        
        ++openFrameCount;
        JPanel toGo;
        Container ct;
              
        switch (name) {
            case "Login":
                LoginGUI l = new LoginGUI();
                ct = l.start(this.getContentPane());
                this.setContentPane(ct);
                setSize(250,200);
                break;
            case "ViewOrder":
                //View Orders
                viewOrderGUI v = new viewOrderGUI();
                toGo = v.start();
                this.setContentPane(toGo);
                setSize(300,300);
                break;
            case "PlaceOrder":
                //Place Order
                placeOrderGUI p = new placeOrderGUI();
                toGo = p.start();
                this.setContentPane(toGo);
                setSize(300,300);
                break;
            default:
                //quit
                oopsGUI o = new oopsGUI();
                toGo = o.start();
                this.setContentPane(toGo);
                setSize(300,300);
                break;
        }

        Name = name;

        //Set the window's location.
        setLocation(xOffset*openFrameCount, yOffset*openFrameCount);
    } 

    public String getName() {
        return Name;
    }
    
}



Once again thanks for any help...

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>