Jump to content

JAVA ImageIcon and JButton resizing problem -- please go easy on me. :)?

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
1 reply to this topic

#1
antitru5t

antitru5t

    Newbie

  • Members
  • Pip
  • 2 posts
Hi everyone,

I am stuck on a JAVA problem again.

I want to figure out how to do a ImageIcon resize.

Here is my following code:


ImageIcon imageClickForMovies = new ImageIcon("clickForMovies1.GIF");

JButton buttonClickForMovies = new JButton(imageClickForMovies);


If anyone can explain to me how to resize the ImageIcon and the Jbutton, that would be great. By the way, I am a very simple-minded person. So, please explain instructions carefully, so that it is in an understandable manner for me.

- Nathe

#2
JerrySpock

JerrySpock

    Newbie

  • Members
  • Pip
  • 9 posts
This is what I did...


JFrame frame = new JFrame("Icon Window");

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setVisible(true);

frame.setSize(200,200);

frame.setLayout(null);

						

ImageIcon buttonIcon = new ImageIcon("ImageIconTestImage.gif");

JButton button = new JButton(buttonIcon);


// X,Y,Length,Width

// Change this to change button size

button.setBounds(30,30,50,50);


frame.add(button);


The important parts of this code are setLayout(null), and button.setBounds. By default JFrame uses BorderLayout, which automatically handles how components (like buttons) are sized and where they're placed. So by setting the layout to null, you're telling JFrame that you want to manually place your button. Button.setBounds tell where exactly you want your button, and it's length and height.

I'm not sure how you would size it if you were using a layout manager.