Created
December 5, 2013 07:21
-
-
Save resarahadian/7801447 to your computer and use it in GitHub Desktop.
Transfer Data JTable
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.JScrollPane; | |
import javax.swing.JTable; | |
import javax.swing.table.DefaultTableModel; | |
import java.awt.event.MouseAdapter; | |
import java.awt.event.MouseEvent; | |
import javax.swing.JLabel; | |
import javax.swing.ImageIcon; | |
import javax.swing.JButton; | |
@SuppressWarnings("serial") | |
public class frameTransferDataTable extends JFrame { | |
private JPanel contentPane; | |
private JScrollPane scrollPaneAtas; | |
private JTable tableAtas; | |
private JScrollPane scrollPaneBawah; | |
private JTable tableBawah; | |
DefaultTableModel tabelModelAtas, tabelModelBawah; | |
String headerAtas[] = {"Nama","Satuan","Harga"}; | |
String recordAtas[][] = {{"Mie Goreng","Bungkus","1800"},{"Susu Ultra","Botol","2500"}, {"Sambal","Botol","12000"}, {"Kecap","Botol","6500"} }; | |
String headerBawah[] = {"No","Nama","Satuan","Harga"}; | |
private JLabel lblWall; | |
private JLabel lblIcon; | |
private JButton btnSimpan; | |
private JButton btnKeluar; | |
/** | |
* Create the frame. | |
*/ | |
public frameTransferDataTable() | |
{ | |
setTitle("Transfer Data Table"); | |
setResizable(false); | |
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); | |
setBounds(100, 100, 790, 509); | |
contentPane = new JPanel(); | |
contentPane.setBorder(new EmptyBorder(5, 5, 5, 5)); | |
setContentPane(contentPane); | |
contentPane.setLayout(null); | |
scrollPaneAtas = new JScrollPane(); | |
scrollPaneAtas.setBounds(45, 12, 512, 169); | |
contentPane.add(scrollPaneAtas); | |
tabelModelAtas = new DefaultTableModel(recordAtas,headerAtas); | |
tableAtas = new JTable(); | |
tableAtas.addMouseListener(new MouseAdapter() { | |
@Override | |
public void mouseClicked(MouseEvent me) { | |
int brs = tableAtas.getSelectedRow(); | |
if(brs == -1) | |
{ | |
return; | |
} | |
String nama = (String) tabelModelAtas.getValueAt(brs, 0); | |
String satuan = (String) tabelModelAtas.getValueAt(brs, 1); | |
String harga = (String) tabelModelAtas.getValueAt(brs, 2); | |
Object[] obj = new Object[4]; | |
obj[1] = nama; | |
obj[2] = satuan; | |
obj[3] = harga; | |
tabelModelBawah.addRow(obj); | |
noTable(); | |
} | |
}); | |
tableAtas.setModel(tabelModelAtas); | |
scrollPaneAtas.setViewportView(tableAtas); | |
scrollPaneBawah = new JScrollPane(); | |
scrollPaneBawah.setBounds(45, 257, 574, 139); | |
contentPane.add(scrollPaneBawah); | |
tabelModelBawah = new DefaultTableModel(null,headerBawah); | |
tableBawah = new JTable(); | |
tableBawah.setModel(tabelModelBawah); | |
scrollPaneBawah.setViewportView(tableBawah); | |
lblIcon = new JLabel(""); | |
lblIcon.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/transferDataTable/icon.png")); | |
lblIcon.setBounds(610, 82, 147, 144); | |
contentPane.add(lblIcon); | |
btnSimpan = new JButton(""); | |
btnSimpan.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/transferDataTable/Simpan.png")); | |
btnSimpan.setBounds(45, 408, 120, 52); | |
contentPane.add(btnSimpan); | |
btnKeluar = new JButton(""); | |
btnKeluar.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/transferDataTable/Hapus.png")); | |
btnKeluar.setBounds(201, 408, 112, 52); | |
contentPane.add(btnKeluar); | |
lblWall = new JLabel(""); | |
lblWall.setIcon(new ImageIcon("/home/resa/Aplikasi Java/SwingJava/src/transferDataTable/wall.png")); | |
lblWall.setBounds(0, -11, 788, 491); | |
contentPane.add(lblWall); | |
setLocationRelativeTo(null); | |
} | |
public void noTable() | |
{ | |
int baris = tabelModelBawah.getRowCount(); | |
for(int a=0; a<baris; a++) | |
{ | |
String nomor = String.valueOf(a+1); | |
tabelModelBawah.setValueAt(nomor + ".", a, 0); | |
} | |
} | |
/** | |
* Launch the application. | |
*/ | |
public static void main(String[] args) { | |
EventQueue.invokeLater(new Runnable() { | |
public void run() { | |
try { | |
UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel"); | |
frameTransferDataTable frame = new frameTransferDataTable(); | |
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