Velocity Reviews

Velocity Reviews (
-   Java (
-   -   setlocation of a JButton on a drawed JFrame (

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:


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);
 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));
public static void main(String [] args)
 MainFrame frame = new MainFrame();
 frame.setSize(500, 500);


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.