Hello, first i love your classes, really making my uni project easier. But i have a question: why does the png not show up in a button, in fact it also moves my word "Print" to the side so not all characters are visible in the button. Why does this happen? should i change button size for a workarouond? Edit: i changed the size with Dimension, but the png is not visible. Another edit: i removed the Dimension code and changed print.png save folder. Now it displays the image (though far too large, but that's not a problem), eclipse seems to not be able to read a .png file, since the image shows with white/gray squares behind it. Am i doing it wrong?
oh found it you can use this ImageIcon printIcon = new ImageIcon(MainFrame.class.getResource("print.png")); button.setIcon(printIcon); NOTE: the file print png should be in same dir as mainframe class and I am using vs code so it should work on other ide s anyway
@philip8989 - Available Fonts are specific to the computer that you are using. Try the code on the following page to list the fonts on your computer: alvinalexander.com/blog/post/jfc-swing/swing-faq-list-fonts-current-platform/ Cheers!
@Chanu Perera - Thank you for the question. You can use absolute positioning as follows: JFrame frame = new JFrame(); JPanel panel = new JPanel(); panel.setLayout(null); JButton jbutton = new JButton("Click"); jbutton.setBounds(10, 10, 75, 25); // x, y, width, height panel.add(jbutton); frame.add(panel); Hope this helps, Cheers!
@amstig_org - This is not really a topic for a beginner but check out the following link for more info. Cheers! harryjoy.me/2011/08/21/different-button-shapes-in-swing/
Taking a little break from the Swing layout managers, in this video we look at the JButton. Please Like, Comment and Subscribe! Cheers!
Great Content and Thank you for this video.
@Kavishka Madhudhan - My pleasure! Glad you enjoyed it! Cheers!
could you make a video of how to round the edges of a jbutton?
@Luiz Alves - Have you looked at the Nimbus look and feel?
@@JavaCodeJunkie I'll look. Is this what NetBeans uses by default?
I really liked the content of the channel, I've already subscribed!
@Luiz Alves - Yes, Nimbus is the Netbeans default look and feel. Thank you for the kind words and the sub! Cheers!
Hello, first i love your classes, really making my uni project easier. But i have a question: why does the png not show up in a button, in fact it also moves my word "Print" to the side so not all characters are visible in the button. Why does this happen? should i change button size for a workarouond?
Edit: i changed the size with Dimension, but the png is not visible.
Another edit: i removed the Dimension code and changed print.png save folder. Now it displays the image (though far too large, but that's not a problem), eclipse seems to not be able to read a .png file, since the image shows with white/gray squares behind it. Am i doing it wrong?
any update lol?
oh found it you can use this
ImageIcon printIcon = new ImageIcon(MainFrame.class.getResource("print.png"));
button.setIcon(printIcon);
NOTE: the file print png should be in same dir as mainframe class and I am using vs code so it should work on other ide s anyway
Thank you @@vedarthjoshi2166
Thank you
hi, where can I find the different font styles like arial etc?
@philip8989 - Available Fonts are specific to the computer that you are using. Try the code on the following page to list the fonts on your computer:
alvinalexander.com/blog/post/jfc-swing/swing-faq-list-fonts-current-platform/
Cheers!
Hello, why my img isn't loaded to the button, the name is already correct.
Hi. I had same problem. The solution was for me: ImageIcon printIcon = new ImageIcon("src/print_small.png");
how to place the button into a specific place?
@Chanu Perera - Thank you for the question. You can use absolute positioning as follows:
JFrame frame = new JFrame();
JPanel panel = new JPanel();
panel.setLayout(null);
JButton jbutton = new JButton("Click");
jbutton.setBounds(10, 10, 75, 25); // x, y, width, height
panel.add(jbutton);
frame.add(panel);
Hope this helps,
Cheers!
@@JavaCodeJunkie wow, this helped . 😌❤ thank you Master.
@Chanu Perera - You are very welcome! I am happy that my suggestion helped you! 🙏
but not show how to change the shape of button
@amstig_org - This is not really a topic for a beginner but check out the following link for more info. Cheers!
harryjoy.me/2011/08/21/different-button-shapes-in-swing/