Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   setlocation of a JButton on a drawed JFrame (http://www.velocityreviews.com/forums/t551116-setlocation-of-a-jbutton-on-a-drawed-jframe.html)

middaycrisis 11-11-2007 07:46 PM

setlocation of a JButton on a drawed JFrame
 
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:

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.


All times are GMT. The time now is 02:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.