Sunday, 29 March 2015

A Tutorial On Set Bounds In Java

This is the method of awt.component class which is used to set the size and position of component.In many tutorial we use flow layout but it puts component in rows according to specified size but some times we need to change the size and position of component then we use this method its general form is given below:

public void setBounds(int x,int y,int width,int height)


  • x defines the  x co-ordinate of componet
  • y defines the y co-ordinate of componet

CODING:

import javax.swing.*;
import java.awt.*;

class tab extends JFrame
{
JButton jb;
tab()
{
super();
setTitle("SetBounds Example");
setSize(400, 300);
setVisible(true);
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);      
jb =new JButton("BUTTON");
setLayout(null);
  jb.setBounds(300, 150, 200, 200);
add(jb);

}

}
class nbutt
{
public static void main(String args[])
{
tab x= new tab();
}

}

OUTPUT:





No comments:

Post a Comment