Advertisement
hafidh

JAVA GUI - Membuat tab di swing

Feb 19th, 2012
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.83 KB | None | 0 0
  1. import javax.swing.*;
  2.  
  3. class ContohTab extends JFrame{
  4.     // attribute
  5.     // membuat panel untuk di tab
  6.     JPanel tab_home;
  7.     JPanel tab_profile;
  8.     JPanel tab_pesan;
  9.    
  10.     // membuat objek tab untuk menampung panel
  11.     JTabbedPane tab;
  12.    
  13.     // membuat label sebagai penanda
  14.     JLabel label_home;
  15.     JLabel label_profile;
  16.     JLabel label_pesan;
  17.    
  18.     // konstruktor
  19.     public ContohTab(){
  20.         //frame seting---------------------------------------------------------------------
  21.         //memanggil konstruktor kelas induk (JFrame)
  22.         super("coba menubar");
  23.         //seting besar frame LEBAR x TINGGI
  24.         this.setSize(300,350);
  25.         //seting agar bisa ditutup
  26.         this.setDefaultCloseOperation(EXIT_ON_CLOSE);
  27.         //seting kemunculan frame di tengah window
  28.         this.setLocationRelativeTo(null);
  29.         //frame seting---------------------------------------------------------------------
  30.         // inisialisasi
  31.         tab_home    = new JPanel();
  32.         tab_profile = new JPanel();
  33.         tab_pesan   = new JPanel();
  34.         tab         = new JTabbedPane();
  35.         label_home  = new JLabel("Anda di tab home");
  36.         label_profile= new JLabel("Anda di tab profile");
  37.         label_pesan = new JLabel("Anda di tab pesan");
  38.        
  39.     }
  40.     public void konfig(){
  41.         // konfigurasi layout panel
  42.         tab_home.setLayout(null);
  43.         tab_profile.setLayout(null);
  44.         tab_pesan.setLayout(null);
  45.         // masukan label ke panel
  46.         tab_home.add(label_home);
  47.         tab_profile.add(label_profile);
  48.         tab_pesan.add(label_pesan);
  49.         // set tata letak label
  50.         label_home.setBounds(10,10,200,30);
  51.         label_profile.setBounds(10,10,200,30);
  52.         label_pesan.setBounds(10,10,200,30);
  53.         // memasukan panel kedalam tab;
  54.         tab.add("home",tab_home);
  55.         tab.add("Profile",tab_profile);
  56.         tab.add("pesan",tab_pesan);
  57.         // memasukan tab kedalam frame
  58.         this.add(tab);
  59.        
  60.     }
  61.     public static void main(String[] args){
  62.         ContohTab tab = new ContohTab();
  63.         tab.konfig();
  64.         tab.show();
  65.     }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement