- Joined
- Nov 11, 2007
- Messages
- 1
- Reaction score
- 0
Hi guys. I've experienced a little problem, when trying to change the location of a JButton, on a g.draw'ed JFrame. setLocation doesn't seem to work. It would be great if you could help me to move this button to where I want
Here's the code:
Thanks for attention.
Here's the code:
Code:
package gui;
import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class MainFrame extends JFrame {
JPanel panel, panel2;
JButton btn, btn2;
JScrollPane scrollPane;
ImageIcon icon, icon2;
Image image;
public MainFrame(){
icon = new ImageIcon("src/gui/bg.jpg");
icon2 = new ImageIcon("src/gui/main_03.jpg");
JPanel panel = new JPanel(){
protected void paintComponent(Graphics g)
{
g.drawImage(icon.getImage(), 0, 0, null);
super.paintComponent(g);
}
};
panel.setOpaque( false );
panel.setSize(500, 500) ;
scrollPane = new JScrollPane( panel );
getContentPane().add( scrollPane );
ImageIcon img = new ImageIcon("src/gui/main_03.jpg");
JButton btn = new JButton(img);
btn.setLocation(230, 20);
btn.setMargin(new Insets(1, 1, 1, 1));
btn.setPreferredSize(new Dimension(256,85));
panel.add(btn);
}
public static void main(String [] args)
{
MainFrame frame = new MainFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500, 500);
frame.setVisible(true);
frame.setTitle("test");
}
}
Thanks for attention.