Created
November 8, 2013 23:13
-
-
Save resarahadian/7379162 to your computer and use it in GitHub Desktop.
Membuat No.urut JTable + Library JTattoo
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
import java.awt.EventQueue; | |
import javax.swing.JFrame; | |
import javax.swing.JPanel; | |
import javax.swing.UIManager; | |
import javax.swing.border.EmptyBorder; | |
import javax.swing.JLabel; | |
import javax.swing.JTextField; | |
import javax.swing.JScrollPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import javax.swing.JButton; | |
import java.awt.event.ActionListener; | |
import java.awt.event.ActionEvent; | |
import javax.swing.ImageIcon; | |
@SuppressWarnings("serial") | |
public class frameNoTable extends JFrame | |
{ | |
private JPanel contentPane; | |
private JTextField txtNama; | |
private JLabel lblNama; | |
private JTextField txtAlamat; | |
private JTextField txtEmail; | |
private JScrollPane scrollPane; | |
private JTable table; | |
DefaultTableModel tabelModel; | |
String header[] = {"No","Nama", "Alamat", "Email"}; | |
private JButton btnTambah; | |
private JButton btnRefresh; | |
private JLabel lblIcon; | |
/** | |
* Create the frame. | |
*/ | |
public frameNoTable() | |
{ | |
setTitle("No Urut Tabel"); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 637, 453); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
lblNama = new JLabel("Nama : "); | |
lblNama.setBounds(12, 18, 70, 15); | |
contentPane.add(lblNama); | |
txtNama = new JTextField(); | |
txtNama.setBounds(86, 12, 196, 27); | |
contentPane.add(txtNama); | |
txtNama.setColumns(10); | |
JLabel lblAlamat = new JLabel("Alamat : "); | |
lblAlamat.setBounds(12, 71, 60, 15); | |
contentPane.add(lblAlamat); | |
txtAlamat = new JTextField(); | |
txtAlamat.setBounds(86, 65, 290, 27); | |
contentPane.add(txtAlamat); | |
txtAlamat.setColumns(10); | |
JLabel lblEmail = new JLabel("Email : "); | |
lblEmail.setBounds(12, 117, 60, 15); | |
contentPane.add(lblEmail); | |
txtEmail = new JTextField(); | |
txtEmail.setBounds(86, 111, 203, 27); | |
contentPane.add(txtEmail); | |
txtEmail.setColumns(10); | |
scrollPane = new JScrollPane(); | |
scrollPane.setBounds(86, 211, 440, 142); | |
contentPane.add(scrollPane); | |
tabelModel = new DefaultTableModel(null, header); | |
table = new JTable(); | |
table.setModel(tabelModel); | |
scrollPane.setViewportView(table); | |
btnTambah = new JButton("Tambah"); | |
btnTambah.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingComponents/src/noTable/Simpan.png")); | |
btnTambah.addActionListener(new ActionListener() | |
{ | |
public void actionPerformed(ActionEvent act) | |
{ | |
Object obj[] = new Object[4]; | |
obj[1] = txtNama.getText(); | |
obj[2] = txtAlamat.getText(); | |
obj[3] = txtEmail.getText(); | |
tabelModel.addRow(obj); | |
noTable(); // Method No Urut Table | |
} | |
}); | |
btnTambah.setBounds(86, 160, 126, 39); | |
contentPane.add(btnTambah); | |
btnRefresh = new JButton("Refresh"); | |
btnRefresh.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingComponents/src/noTable/refresh.png")); | |
btnRefresh.addActionListener(new ActionListener() { | |
public void actionPerformed(ActionEvent act) | |
{ | |
txtNama.setText(""); | |
txtAlamat.setText(""); | |
txtEmail.setText(""); | |
txtNama.requestFocus(); | |
} | |
}); | |
btnRefresh.setBounds(236, 160, 117, 39); | |
contentPane.add(btnRefresh); | |
lblIcon = new JLabel(""); | |
lblIcon.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingComponents/src/noTable/icon.png")); | |
lblIcon.setBounds(428, 18, 153, 134); | |
contentPane.add(lblIcon); | |
setLocationRelativeTo(null); | |
} | |
//No Urut Table | |
public void noTable() | |
{ | |
int baris = tabelModel.getRowCount(); | |
for(int a=0; a<baris; a++) | |
{ | |
String nomor = String.valueOf(a+1); | |
tabelModel.setValueAt(nomor + ".", a, 0); | |
} | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
com.jtattoo.plaf.aluminium.AluminiumLookAndFeel.setTheme("Large-Font", "Java Swing", ""); | |
UIManager.setLookAndFeel("com.jtattoo.plaf.aluminium.AluminiumLookAndFeel"); | |
frameNoTable frame = new frameNoTable(); | |
frame.setVisible(true); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment