// You might want to add frame.setVisible(true) to be the very last line. Sometimes with Mac, the components won't appear until you resize the window import java.awt.Color; import java.awt.Font; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; public class Main { public static void main(String[] args) { // JLabel = a GUI display area for a string of text, an image, or both ImageIcon image = new ImageIcon("dude.png"); Border border = BorderFactory.createLineBorder(Color.green,3); JLabel label = new JLabel(); //create a label label.setText("bro, do you even code?"); //set text of label label.setIcon(image); label.setHorizontalTextPosition(JLabel.CENTER); //set text LEFT,CENTER, RIGHT of imageicon label.setVerticalTextPosition(JLabel.TOP); //set text TOP,CENTER, BOTTOM of imageicon label.setForeground(new Color(0x00FF00)); //set font color of text label.setFont(new Font("MV Boli",Font.PLAIN,100)); //set font of text label.setIconTextGap(-25); //set gap of text to image label.setBackground(Color.black); //set background color label.setOpaque(true); //display background color //label.setBorder(border); //sets border of label (not image+text) label.setVerticalAlignment(JLabel.CENTER); //set vertical position of icon+text within label label.setHorizontalAlignment(JLabel.CENTER); //set horizontal position of icon+text within label //label.setBounds(100, 100, 250, 250); //set x,y position within frame as well as dimensions JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setSize(500,500); //frame.setLayout(null); frame.setVisible(true); frame.add(label); frame.pack(); } }
@jhanzaibhumayun57823 жыл бұрын
Thanks for the tip! My labels were not showing up until I resized the window. This explains why. Using IntelliJ IDEA.
@shanihalder27553 жыл бұрын
@@jhanzaibhumayun5782 bro can u help me pls by telling what u exactly did? Im also using intellij and facing the problem, tried different ways, but imageicon is not showing up, text is coming but imageicon never shows 😭, pls help bro, what to do
@jhanzaibhumayun57823 жыл бұрын
@@shanihalder2755 I just added frame.setVisible(true) to the last line in the code. Don't really know exactly what type of problem you are having. Would help if you posted your code.
@scientificshorts96733 жыл бұрын
in the previous lesson .setopaque wasn't used change color of the frame but is it used here?
@shanihalder27553 жыл бұрын
@@jhanzaibhumayun5782 problem solved bro after multiple tries. It solved after i moved the image to the project folder, earlier i was putting the image in the source code folder. Thanks for help❤️
@pavelkvasnicka6856 Жыл бұрын
This is the best Java tutorial for beginners, so you can learn Java and English in one hit. Please keep going! I vote for Java advance tutorial. Thanks a lot Bro
@caidenhiles Жыл бұрын
Knowing that you made a video about labels actually exited me to learn about labels and I thought about it all day today and yesterday until I finally got a chance to watch it tonight. Gotta say, it's my favorite tutorial i've watched
@augustocera5743 жыл бұрын
Thank you very much Bro. Your tutorials are fantastic. Your so underrated man...
@Iischeese2 жыл бұрын
If the Image Icon is not showing up you can try: 'ImageIcon *name* = new ImageIcon(getClass().getResource("*FilePath*"));' instead of 'ImageIcon *name * = new ImageIcon(*FilePath*);'
@thaison3684 Жыл бұрын
bro u can help me. my error : Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.net.URL.toExternalForm()" because "location" is null
@Iischeese Жыл бұрын
@@thaison3684 looks like something that you code is trying to reference is null. Try seeing if you are referencing/declaring correctly.
@Tamflakes Жыл бұрын
Bless you, I was going crazy!! That did the trick! 🤯
@Iischeese Жыл бұрын
@@Tamflakes No problem, glad I could help!
@zohebansari6429 Жыл бұрын
Bro it is showing " non static method "getclass()" tell me without using method how to bring images??
@maxwong17682 жыл бұрын
This lesson has much more information than usual . I have made some references for each code and would like to share with you guys . Hope this will make it more clear to you . package testing; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.border.Border; import javax.swing.BorderFactory; import java.awt.Color; import java.awt.Font; public class Main { public static void main(String[] args) { // create an image for label . ImageIcon image = new ImageIcon("src/烈日戰士.png") ; // create boundary lines for label and set their color and size . Border border = BorderFactory.createLineBorder(new Color(0x000000) , 5) ; // Setup the label // create a label . JLabel label = new JLabel() ; label.setBackground(new Color(0xABF095)) ; // It is used after setting the background color . // true : paint every pixel within the bounds of label . label.setOpaque(true) ; // Apply the boundary lines to the label . label.setBorder(border) ; // set the position and dimensions of label bounds within the frame . // Before using the code below , add to set a layout for label first . label.setBounds(0 , 0 , 500 , 500) ; // (x , y , width , height) // Text of label // Another style : label.setText("Nice to meet you !"); // set "type of font" , font style , font size . // ("MV Boli" , "Helvetica" , "Futura" , ……) , (plain, bold, italic) label.setFont(new Font("MV Boli" , Font.PLAIN , 20)) ; // set the font color . label.setForeground(new Color(0x4878F5)) ; // Position of components in label // add the image into the label . label.setIcon(image) ; // set the position of label text within the label bounds . label.setHorizontalTextPosition(JLabel.CENTER) ; // Left or CENTER or RIGHT label.setVerticalTextPosition(JLabel.TOP) ; // TOP or CENTER or BOTTOM // set the position of label image within the label bounds . label.setHorizontalAlignment(JLabel.CENTER) ; label.setVerticalAlignment(JLabel.CENTER) ; // set the distance between the text block and the image . // negative and positive are both available . label.setIconTextGap(0) ; // Setup the frame . // we need a frame to hold components(e.g. label) . JFrame frame = new JFrame() ; frame.setVisible(true) ; // exit when you click [X] on the top-right corner . // "JFrame.HIDE_ON_CLOSE" : hide but still running in the background thread . //"JFrame.DO_NOTHING_ON_CLOSE" : disable the [X] button . frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE) ; frame.setSize(500 , 500) ; // still manually resizable . // Add component to the frame . frame.add(label) ; // set a layout for the label to set bounds . frame.setLayout(null) ; // By using the code below , system will auto-resize the frame in order to accommodate all the components you add to the frame , no matter if size of components change . // use to add all your components to your frame first , disable and before you use the code below . // frame.pack() ; } }
@ADJOLU91 Жыл бұрын
This was soo difficult to understand at school but somehow you make it sooo easy. Thank you! 🙏🏼
@swapnil729 ай бұрын
From Java17 onwards use "LEADING" instead of "TOP" to avoid exception
@UnderArea512 жыл бұрын
Awesome! I love the broke down videos - learn Java in smaller sections
@somonorhong1686 ай бұрын
you're the best teacher , Thanks for this vdo
@dianamilenaarchilacordoba46323 ай бұрын
great video!!! I'm infinitely grateful for your dedication and big heart to share this knowledge with the world. Thank you soo much
@mbekezelisibanda36412 жыл бұрын
bro your tutorials are so much helpfull its well detailed for a beginner like me .
@RockRahul0103 Жыл бұрын
Much needed thing in KZbin thanks bro
@Ryan-zv6yl5 ай бұрын
Makes me really appreciate JavaScript with css. This would have taken me like 8 lines of css to accomplish this. Great to have this option in Java thiugh
@kemann38153 жыл бұрын
Wow. Awesome.
@legiang58367 ай бұрын
thank you sir
@danny.30363 жыл бұрын
Thanks, Bro! ☕ You're awesome!
@kamalkhashoggi23742 жыл бұрын
Thank yo brother I understand now what is a Label is ow to create a label and what is a frame and how to create a Frame. Millions Thanks and god bless you❤
@cdjosh35684 жыл бұрын
Very good video keep it up!
@BroCodez4 жыл бұрын
thanks for watching Josh!
@mahdib93614 жыл бұрын
Please Make Tuturial For JAVAFX
@Simis9992 жыл бұрын
we're gettin higher bro!!
@janil93574 жыл бұрын
very helpful as always thank you !!
@Amirrjl-y8z Жыл бұрын
nice
@lucyledezma7094 жыл бұрын
Hey Bro!!! Thanks so much for the tutorial!!!!
@BroCodez4 жыл бұрын
you're welcome! Thanks for watching!
@noisyguest52494 жыл бұрын
I use to think and java and javascript was the same when i first strarted coding hahah
@BroCodez4 жыл бұрын
I did too lol. I guess Javascript was named after Java because the name was so popular at the time, albeit Javascript has nothing to do with Java
@noisyguest52494 жыл бұрын
@@BroCodez ohhh i learned js beforr java becuz of it
@parthibanv.p55623 жыл бұрын
Yeah I'm also confused when I'm started Java. I bought javascript course in Udemy instead of Java course .
@umamahesh19913 жыл бұрын
Me tooo.....bro explanation 👌..take a bow
@beksaylor2 жыл бұрын
@Bro Code I am learning more from you than I am my professors. Thanks Bro~~
@adriannedayrilleilaban92243 жыл бұрын
bro how do you add another text so that there is a text above and below the pic?
@robinshere86973 жыл бұрын
Thank you bro! Great content and explainations.
@upcomingupdateswithsajju77253 жыл бұрын
Sir please tell us in short how to add an image to the project folder? Thank you sir
@tobias66422 жыл бұрын
Copy the image from the explorer and then in Eclipse, select the package and hit ctr + v to paste it. Alternatively you can copy the absolute path of the image if you don't want to paste it in the project folder.
@Maximiliano7062 жыл бұрын
Thank You !
@WajdAlhuzaym2 жыл бұрын
thank you very much bro, you're more helpfulI than university lectures
@Benchmus3 жыл бұрын
I need this Chanel, because java is complicated
@ahmedmelsapagh66114 жыл бұрын
Very very good
@BroCodez4 жыл бұрын
thanks for watching Ahmed
@malikshahzaib33134 жыл бұрын
Thank you brother!
@曾毓哲-b1t Жыл бұрын
Thank you very much
@studioboi1772 ай бұрын
thank u bro
@BISAMARKSMANDOANG Жыл бұрын
GG
@md.sazibahmed86594 жыл бұрын
Best
@BroCodez4 жыл бұрын
thanks for watching MD. Sazib
@mohamadnazirissumalgy36994 жыл бұрын
I'm keen on your videos bro.
@BroCodez4 жыл бұрын
thank you for watching Mohamad
@a7mibr20611 ай бұрын
Thanks Bro
@魏子強-z7s Жыл бұрын
thank you bro myhero
@yahyakhawaja882 жыл бұрын
How can I resize the image in a label. I palced a random image it only a part of it appeared in the label
@shaikadil2197 Жыл бұрын
To resize the image icon, you'll have to translate the icon to an image, resize the image then translate the the image back to an icon. Here's the code ; ImageIcon icon = new ImageIcon (filename.png): Image image = icon.getImage(); //transform the icon to an image. Image newimage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH): icon=new ImageIcon(newimage);// this transforms the image back to an icon credit: Martin Wachira(Comments)
@mahmodmardani75353 жыл бұрын
perfect
@AliZografos10 ай бұрын
how can i add only the image and move it around the frame?
@853kryptonian74 жыл бұрын
How to set an image as your the logo for the app you have programmed?
@ibrahimylmaz83782 жыл бұрын
thanks bro
@manuelgonzalezpalafox26272 жыл бұрын
Ly 2 bro
@kingkock12 жыл бұрын
Label of love
@sophieguelfi8193 Жыл бұрын
how can i make the image smaller on my screen?
@shaikadil2197 Жыл бұрын
To resize the image icon, you'll have to translate the icon to an image, resize the image then translate the the image back to an icon. Here's the code ; ImageIcon icon = new ImageIcon (filename.png): Image image = icon.getImage(); //transform the icon to an image. Image newimage = image.getScaledInstance(width, height, Image.SCALE_SMOOTH): icon=new ImageIcon(newimage);// this transforms the image back to an icon credit: Martin Wachira(Comments)
@fiona76512 жыл бұрын
Thanks!!
@minhtetpaing16953 жыл бұрын
Thank you so much sir.
@mudassirnaz18133 жыл бұрын
Thanks
@bgtstudy80394 жыл бұрын
Thanks You so so so so so so so much..
@rentv64472 жыл бұрын
Thankyou Bro😍
@James_AAF7 ай бұрын
for the algorithm
@amankrmj3 жыл бұрын
Sir, is it possible to create array of JLabels....?
@ryan2-5183 жыл бұрын
Yeah Jlabel[] labelArray = new Jlabel[whatever size you want]
@mahorodivin2979 Жыл бұрын
thx bro
@cadmvwebteam40274 жыл бұрын
My gui window pop up does not have the Java Logo on the left top? How to set up so that this Java Logo should appear on the left top? Instead of the Java Logo on top left, all I see just: X, -, and + signs on the left. Is there a way to move those to the right top so that we can set up the Java Logo on the left top. Thanks for helping...
@BroCodez4 жыл бұрын
are you referring to the default java logo?
@honoredegg2 жыл бұрын
50th. Thank you, ma Bro Sensei
@853kryptonian74 жыл бұрын
PLz bro how to set an image as your logo
@619REY384 жыл бұрын
is there a code to resize the image icon?
@martinwachira44292 жыл бұрын
To resize the image icon, you'll have to translate the icon to an image, resize the image then translate the the image back to an icon. Here's the code ; ImageIcon icon = new ImageIcon (filename.png): Image image = icon.getImage() //transform the icon to an image. Image newimage = image.getScaledInstance(width, height, Image SCALE_SMOOTH): icon = new ImageIcon (newimage);// this transforms the image back to an icon.
@shaikadil2197 Жыл бұрын
@@martinwachira4429 Thanks a lot brother. It worked!!
@bryansuguitan76166 ай бұрын
Guys, my favicon isn't showing on my JFrame. I am using netbeans on mac OS. How can I make it work?
@blankcoder235 Жыл бұрын
ImageIcon doesn't work. Give some suggestion
@КоляСмоляр-м7л2 жыл бұрын
where i can find fonts types for label
@maryamhussein2192 Жыл бұрын
you are the goat! T ^ T :DDD
@Mo_Xtreme3 жыл бұрын
How do you add a jpeg file in intellij idea? Help please
@mamaafrica25122 жыл бұрын
how can I add second label?
@sithuhtun36093 жыл бұрын
The font style doesn't work. I need help
@geocojonnrigor2 жыл бұрын
Thanks for the tutorial. But I have a question. Why is it when I run the program the GUI's Appearance doesn't update, it's just empty/blank white window. It just gets updated or fixed whenever I just resize the window's size or hit maximize or minimize button. I mean it's not a big deal, but just annoying since I have to do that whenever I need to run the code.
@soumelee56612 жыл бұрын
try putting the frame.setVisible(true); at the end of the code
@geocojonnrigor2 жыл бұрын
@@soumelee5661 I already found the solution on the error! 😅 But thank you!
@tinczo11782 жыл бұрын
yo its me fellow bro
@061_SHIVANSHSRIVASTAVA3 ай бұрын
ok
@abishekk.j37732 жыл бұрын
I Coded on my VS but its not getting any effect in Frame even though I added label to Frame? Anyone know why that is happening?
@raghavkonda61752 жыл бұрын
Isnt doing all this in Java , a little complicated. Can be done with less effort with CSS and Front end Javascript ... Whats your opinion ?
@Mix_Lv Жыл бұрын
a little late, but this is a java course man, why would he do it in CSS or JavaScript in a Java course. Doesnt matter if its complicated.
@lenoxi2735 ай бұрын
My Images aren't visible pls help🙏
@leonidas147756 ай бұрын
Java has Labels... it also has goto 👹
@seabass61064 жыл бұрын
Bro you make me Pro
@jacokyle01603 жыл бұрын
Hey bro, I copy and pasted all your code into my VScode editor and swapped the bro.png reference with a different image in my project folder-- but the image didn't show on the screen. Do you know an easy fix to this? It's really been bothering me.
@jacokyle01603 жыл бұрын
Ah, I got it to work. Thanks for the vids man- they are really the only resource out there to learn this kind of stuff
@dipikakanth84023 жыл бұрын
I'm having the same problem..could you please help me out ??
@jacokyle01603 жыл бұрын
@@dipikakanth8402 I fixed the issue by putting my image in the project folder-- not the library folder or the source code folder, but the main folder.
@dipikakanth84023 жыл бұрын
@@jacokyle0160 Thank you
@Pellucoxx3 жыл бұрын
Bro, please add code to comment!
@noisyguest52494 жыл бұрын
I code but not in binary numbers
@BroCodez4 жыл бұрын
that is ok, I don't either
@ap1136-c4m8 ай бұрын
@joyceasante8292 Жыл бұрын
import java.awt.Font; import java.awt.Color; import javax.swing.BorderFactory; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.border.Border; public class Main{ public static void main(String[ ]args){ ImageIcon image = new ImageIcon("flower.png"); Border border = BorderFactory.createLineBorder(Color.blue,3); JLabel label = new JLabel(); label.setText("Coding is fun!"); label.setIcon(image); label.setHorizontalTextPosition(JLabel.RIGHT); label.setVerticalTextPosition(JLabel.CENTER); label.setForeground(Color.blue); label.setFont(new Font("Italic",Font.ITALIC,18)); label.setIconTextGap(-20); label.setBackground(Color.yellow); label.setOpaque(true); label.setBorder(border); label.setVerticalAlignment(JLabel.BOTTOM); label.setHorizontalAlignment(JLabel.LEFT); //label.setBounds(50,50,125,125); JFrame frame = new JFrame(); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //frame.setSize(380,380); //frame.setLayout(null); frame.add(label); frame.setVisible(true); frame.pack(); } }
@SuperMixGamer3 жыл бұрын
where's the code tho
@JohnSmithM2C3 жыл бұрын
Bro,do u even code?
@siriusleto37582 жыл бұрын
2. comment
@patrickpasaje40373 жыл бұрын
"Video 50"
@lorenzschwarz58773 жыл бұрын
comment
@bobzerotz55393 жыл бұрын
random comment
@noah774 жыл бұрын
Seems like you have cough, everything alright??
@ramarromarrone77564 жыл бұрын
bruv it's his voice
@BroCodez4 жыл бұрын
My voicebox was wornout. Two videos/day might be too much lol
@unofficialbeastx9294 жыл бұрын
You = God
@BroCodez4 жыл бұрын
thanks, but I'm just bro
@etsoo3 жыл бұрын
.
@greeneggsandmushrooms98553 жыл бұрын
a buh abuh dat's all fokes
@raulmartinez2361 Жыл бұрын
idk why but my code wont load any image some of the var names are diffrent then the video but it just wont load and idk why package Main; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class mayn { public static void main(String[] args) { ImageIcon bg = new ImageIcon("computationalemulatorr calc2.png"); JLabel textz = new JLabel(); textz.setText("GOD HELP ME PLEASE, GIVE ME STRENGTH"); textz.setIcon(bg); JFrame window = new JFrame(); window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); window.setSize(32*48,32*24); window.add(textz); window.setVisible(true); } }
@zohebansari6429 Жыл бұрын
Sams problem bro why I can't use label.add(image)?? You got solution