iamthwee
Posting Expert
5,950 posts since Aug 2005
Reputation Points: 1,543
Solved Threads: 439
Thanks for the help but now I'm pulling my hair out with another thing.... How do I properly position a button (or anything else), and have it at a locked size? Also how do I lock jframe?
I have given you simple code to positioning a button ok just look at this one..
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class a extends JFrame
{
// Variables declaration
private JButton jButton1;
private JPanel contentPane;
// End of variables declaration
public a()
{
super();
initializeComponent();
this.setVisible(true);
}
private void initializeComponent()
{
jButton1 = new JButton();
contentPane = (JPanel)this.getContentPane();
jButton1.setBackground(new Color(182, 169, 92));
jButton1.setText("jButton1");
jButton1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e)
{
jButton1_actionPerformed(e);
}
});
contentPane.setLayout(null);
addComponent(contentPane, jButton1, 140,107,83,28);
this.setTitle("a - extends JFrame");
this.setLocation(new Point(0, 0));
this.setSize(new Dimension(390, 300));
}
private void addComponent(Container container,Component c,int x,int y,int width,int height)
{
c.setBounds(x,y,width,height);
container.add(c);
}
private void jButton1_actionPerformed(ActionEvent e)
{
System.out.println("\njButton1_actionPerformed(ActionEvent e) called.");
}
` public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
}
catch (Exception ex)
{
System.out.println("Failed loading L&F: ");
System.out.println(ex);
}
new a();
}
}
vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7
addComponent(contentPane, jButton1, 140,107,83,28);
by changing these four values 140,107,83,28
you can change the position and size of the button
vinod_javas
Practically a Posting Shark
871 posts since Feb 2007
Reputation Points: 119
Solved Threads: 7