JLabel label1 = new JLabel("Welcome to.."); label1.setBounds(130, 49, 99, 14); getContentPane().add(label1); label1.getText(); // get ค่า label1.setText(String); // set ค่า
package com.java.myapp; import java.awt.EventQueue; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; public class MyForm extends JFrame { /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() { MyForm frame = new MyForm(); frame.setVisible(true); } }); } /** * Create the frame. */ public MyForm() { setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setBounds(100, 100, 362, 249); setTitle("ThaiCreate.Com Java GUI Tutorial"); getContentPane().setLayout(null); // Label 1 JLabel label1 = new JLabel("Welcome to.."); label1.setBounds(130, 49, 99, 14); getContentPane().add(label1); // Label 2 JLabel label2 = new JLabel(); label2.setText("ThaiCreate.Com"); label2.setBounds(111, 74, 128, 14); label2.setHorizontalTextPosition(JLabel.CENTER); getContentPane().add(label2); // Label 3 (Icon) JLabel lbl3 = new JLabel(new ImageIcon(getClass().getResource("save.gif"))); lbl3.setBounds(142, 119, 46, 14); getContentPane().add(lbl3); } }
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท