Last active
May 14, 2021 12:24
-
-
Save tuxcuiabano/0f7281f951b78657ae5dee4ae33d50fd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author tuxcuiabano | |
*/ | |
import java.awt.FlowLayout; // specifies how components are arranged | |
import javax.swing.JFrame; // provides basic window features | |
import javax.swing.JLabel; // displays text and images | |
import javax.swing.SwingConstants; // common constants used with Swing | |
import javax.swing.Icon; // interface used to manipulate images | |
import javax.swing.ImageIcon; // loads images | |
public class LabelFrame extends JFrame | |
{ | |
private JLabel label1; // JLabel with just text | |
private JLabel label2; // JLabel constructed with text and icon | |
private JLabel label3; // JLabel with added text and icon | |
// LabelFrame constructor adds JLabels to JFrame | |
public LabelFrame() | |
{ | |
super( "Testando JLabel" ); | |
setLayout( new FlowLayout() ); // set frame layout | |
// JLabel constructor with a string argument | |
label1 = new JLabel( "Label com texto" ); | |
label1.setToolTipText( "Esse é o label1" ); | |
add( label1 ); // add label1 to JFrame | |
// JLabel constructor with string, Icon and alignment arguments | |
Icon bug = new ImageIcon( getClass().getResource( "logo.png" ) ); | |
label2 = new JLabel( "Label com texto e ícone", bug, | |
SwingConstants.LEFT ); | |
label2.setToolTipText( "Esse é o label2" ); | |
add( label2 ); // add label2 to JFrame | |
label3 = new JLabel(); // JLabel constructor no arguments | |
label3.setText( "Label com texto e ícone com posicionamento inferior (bottom)" ); | |
label3.setIcon( bug ); // add icon to JLabel | |
label3.setHorizontalTextPosition( SwingConstants.CENTER ); | |
label3.setVerticalTextPosition( SwingConstants.BOTTOM ); | |
label3.setToolTipText( "Esse é o label3" ); | |
add( label3 ); // add label3 to JFrame | |
} // end LabelFrame constructor | |
} // end class LabelFrame |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @author tuxcuiabano | |
*/ | |
import javax.swing.JFrame; | |
public class LabelTest | |
{ | |
public static void main( String[] args ) | |
{ | |
LabelFrame labelFrame = new LabelFrame(); // create LabelFrame | |
labelFrame.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE ); | |
labelFrame.setSize( 260, 180 ); // set frame size | |
labelFrame.setVisible( true ); // display frame | |
} // end main | |
} // end class LabelTest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment