JButton | Java Swing Tutorial for Beginners

Поділитися
Вставка
  • Опубліковано 9 лис 2024

КОМЕНТАРІ • 23

  • @JavaCodeJunkie
    @JavaCodeJunkie  3 роки тому +3

    Taking a little break from the Swing layout managers, in this video we look at the JButton. Please Like, Comment and Subscribe! Cheers!

  • @kavishkamadhudhan1943
    @kavishkamadhudhan1943 2 роки тому

    Great Content and Thank you for this video.

    • @JavaCodeJunkie
      @JavaCodeJunkie  2 роки тому

      @Kavishka Madhudhan - My pleasure! Glad you enjoyed it! Cheers!

  • @luizalves2308
    @luizalves2308 3 роки тому +1

    could you make a video of how to round the edges of a jbutton?

    • @JavaCodeJunkie
      @JavaCodeJunkie  3 роки тому +1

      @Luiz Alves - Have you looked at the Nimbus look and feel?

    • @luizalves2308
      @luizalves2308 3 роки тому +2

      @@JavaCodeJunkie I'll look. Is this what NetBeans uses by default?
      I really liked the content of the channel, I've already subscribed!

    • @JavaCodeJunkie
      @JavaCodeJunkie  3 роки тому +2

      @Luiz Alves - Yes, Nimbus is the Netbeans default look and feel. Thank you for the kind words and the sub! Cheers!

  • @adodoes8770
    @adodoes8770 Рік тому +1

    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?

    • @vedarthjoshi2166
      @vedarthjoshi2166 Рік тому

      any update lol?

    • @vedarthjoshi2166
      @vedarthjoshi2166 Рік тому

      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

    • @chaimaelbesri3126
      @chaimaelbesri3126 2 місяці тому +1

      Thank you ​@@vedarthjoshi2166

  • @rezahajivand7498
    @rezahajivand7498 Рік тому

    Thank you

  • @philipT8989
    @philipT8989 3 роки тому +1

    hi, where can I find the different font styles like arial etc?

    • @JavaCodeJunkie
      @JavaCodeJunkie  3 роки тому +1

      @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!

  • @christianlimiwijaya3942
    @christianlimiwijaya3942 5 місяців тому

    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");

  • @chanuperera
    @chanuperera 2 роки тому +1

    how to place the button into a specific place?

    • @JavaCodeJunkie
      @JavaCodeJunkie  2 роки тому +3

      @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!

    • @chanuperera
      @chanuperera 2 роки тому +1

      @@JavaCodeJunkie wow, this helped . 😌❤ thank you Master.

    • @JavaCodeJunkie
      @JavaCodeJunkie  2 роки тому +1

      @Chanu Perera - You are very welcome! I am happy that my suggestion helped you! 🙏

  • @amstig_org338
    @amstig_org338 2 роки тому

    but not show how to change the shape of button

    • @JavaCodeJunkie
      @JavaCodeJunkie  2 роки тому +1

      @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/