Results 1 to 3 of 3
- 11-24-2010, 11:01 AM #1
Member
- Join Date
- Nov 2010
- Posts
- 10
- Rep Power
- 0
Help: How to auto-resize the image icon to fit in the jlabel
Hi, anyone knows how to code to auto-resize the image icon to auto-fit into jLabel.
Here is my code for my button:
private JButton getJButtonSignUp() {
if (jButtonSignUp == null) {
jButtonSignUp = new JButton();
jButtonSignUp.setBounds(new Rectangle(270, 497, 133, 50));
jButtonSignUp.setIcon(new ImageIcon(getClass().getResource("/images/button.png")));
jButtonSignUp.setFont(new Font("Arial", Font.PLAIN, 14));
jButtonSignUp.setHorizontalTextPosition(SwingConst ants.CENTER);
jButtonSignUp.setForeground(Color.black);
jButtonSignUp.setText("Sign Up");
jButtonSignUp.setContentAreaFilled(false);
jButtonSignUp.setBorder(BorderFactory.createEmptyB order(2, 2, 2, 2));
}
return jButtonSignUp;
}
Thanks.
- 11-24-2010, 01:23 PM #2
1. Your question asks about a JLabel (wrongly spelled jLabel) and your code relates to a JButton
2. Don't double post the same question.
http://www.java-forums.org/new-java/...it-jlabel.html
3. A JLabel or JButton computes its preferred size according to is icon and/or text. If you need an image size that depends on the size of the component it is displayed in, custom painting may be a better option.
Lesson: Performing Custom Painting (The Java™ Tutorials > Creating a GUI With JFC/Swing)
db
- 11-24-2010, 02:38 PM #3
Member
- Join Date
- Nov 2010
- Posts
- 10
- Rep Power
- 0
Similar Threads
-
How to resize images to fit JLabel?
By Krooger in forum New To JavaReplies: 3Last Post: 11-24-2010, 01:22 PM -
can't resize my JLabel
By gib65 in forum AWT / SwingReplies: 10Last Post: 06-25-2010, 05:30 AM -
JTable Auto Resize Mode - not working as I expect
By pahiker in forum AWT / SwingReplies: 5Last Post: 06-17-2010, 08:03 AM -
JScrollpane auto resize
By knuth in forum New To JavaReplies: 3Last Post: 09-29-2009, 10:12 PM -
Window resize icon...
By pele in forum SWT / JFaceReplies: 3Last Post: 06-09-2008, 08:31 AM
Bookmarks