tags:

views:

93

answers:

2

hii every one,

following is my code which displays 4 panel

one is at NORTH,....WEST , SOUTH

i want to display am image at EAST at container

how is it possible?

public class ImageProcessor extends JApplet {



JPanel panel1,panel2,panel3,panel4,panel5;
JTextField nameTxt,addTxt,phoneTxt,emailTxt;
JButton capture,download,cancle,sendEmail;
JLabel head,name,add,phone,email;


//function to align components using gridBagLayOut..
    private GridBagConstraints getConstraints(int gridx, int gridy,int gridwidth, int gridheight, int anchor)
    {
        GridBagConstraints c =new GridBagConstraints();
        c.insets = new Insets(10,10,10,10);
        c.ipadx = 0;
        c.ipady = 0;
        c.gridx = gridx;
        c.gridy = gridy;
        c.gridwidth = gridwidth;
        c.gridheight = gridheight;
        c.anchor = anchor;
        return c;
    }
//ends here...



public void init() {


    panel1 = new JPanel();
    panel2 = new JPanel();
    panel3 = new JPanel();
    panel4 = new JPanel();
    panel5 = new JPanel();

    nameTxt = new JTextField(20);
    addTxt = new JTextField(20);
    phoneTxt = new JTextField(20);
    emailTxt = new JTextField(20);

    capture = new JButton("capture");
    download = new JButton("download");
    sendEmail = new JButton("sendEmail");

    head = new JLabel("BUSINESS CARD READER");
    name = new JLabel("NAME:");
    add = new JLabel("ADDRESS:");
    phone = new JLabel("PHONE:");
    email = new JLabel("EMAIL:");

    Container myPane = getContentPane();
    myPane.setLayout(new BorderLayout());

    panel1.setLayout(new BorderLayout());



    panel2.setLayout(new GridBagLayout());
    panel2.add(head,getConstraints(0,0,1,1,GridBagConstraints.CENTER));

    panel3.setLayout(new FlowLayout());
    panel3.add(capture);
    panel3.add(download);
    panel3.add(sendEmail);

    panel4.setLayout(new GridBagLayout());

    panel4.add(name,getConstraints(0,0,1,1,GridBagConstraints.CENTER));
    panel4.add(nameTxt,getConstraints(1,0,1,1,GridBagConstraints.CENTER));

    panel4.add(add,getConstraints(0,1,1,1,GridBagConstraints.CENTER));
    panel4.add(addTxt,getConstraints(1,1,1,1,GridBagConstraints.CENTER));

    panel4.add(phone,getConstraints(0,2,1,1,GridBagConstraints.CENTER));
    panel4.add(phoneTxt,getConstraints(1,2,1,1,GridBagConstraints.CENTER));

    panel4.add(email,getConstraints(0,3,1,1,GridBagConstraints.CENTER));
    panel4.add(emailTxt,getConstraints(1,3,1,1,GridBagConstraints.CENTER));


    panel1.add(panel2,BorderLayout.NORTH);
    panel1.add(panel3,BorderLayout.SOUTH);
    panel1.add(panel4,BorderLayout.WEST);
    panel1.add(panel5,BorderLayout.EAST);
    setSize(500,500);
    myPane.add(panel1,BorderLayout.CENTER);


}
public void start(){
    this.setSize(800,500);

}

}

+2  A: 

Create a JLabel without text ("") and use setIcon to set the image to be displayed.

Here is an example.

Peter Lang
... or use the JLabel(Icon image) constructor
Fortega
Thanks its work
Hussain
+1  A: 

Add the picture on a JButton or JLabel to your panel5:

JButton buttonForPicture = new JButton();
buttonForPicture.setBorder(new EmptyBorder(0, 0, 0, 0));
buttonForPicture.setOpaque(false);
buttonForPicture.setIcon(new ImageIcon(imageFilePath));
panel5.add(buttonForPicture);
Bruno Rothgiesser
Thanks its work
Hussain