Coba pelajari code dibawah ini, intinya pada text yang bercetak tebal import java.awt.Point; import java.awt.Rectangle;
/* * Scroller.java * * Created on 20 Februari 2008, 13:48 */ /** * * @author Vanya Terra Ardani */ public class Scroller extends javax.swing.JFrame { /** Creates new form Scroller */ public Scroller() { initComponents(); jTable1.getSelectionModel().setSelectionInterval(0, 0); updateButton(); } /** This method is called from within the constructor to * initialize the form. * WARNING: Do NOT modify this code. The content of this method is * always regenerated by the Form Editor. */ // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents private void initComponents() { jScrollPane1 = new javax.swing.JScrollPane(); jTable1 = new javax.swing.JTable(); jButton1 = new javax.swing.JButton(); jButton2 = new javax.swing.JButton(); jButton3 = new javax.swing.JButton(); jButton4 = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); jTable1.setModel(new javax.swing.table.DefaultTableModel( new Object [][] { {"01", "Agus"}, {"02", "Andi"}, {"03 ", "Budi"}, {"04", "Cody"}, {"05", null}, {"06", null}, {"07", null}, {"08", null}, {"09", null}, {"10", ""} }, new String [] { "ID", "Name" } )); jTable1.setAutoscrolls(false); jTable1.addMouseListener(new java.awt.event.MouseAdapter() { public void mouseClicked(java.awt.event.MouseEvent evt) { jTable1MouseClicked(evt); } }); jTable1.addMouseMotionListener(new java.awt.event.MouseMotionAdapter() { public void mouseDragged(java.awt.event.MouseEvent evt) { jTable1MouseDragged(evt); } }); jTable1.addKeyListener(new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { jTable1KeyReleased(evt); } }); jScrollPane1.setViewportView(jTable1); jButton1.setText("|<"); jButton1.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton1ActionPerformed(evt); } }); jButton2.setText("<<"); jButton2.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton2ActionPerformed(evt); } }); jButton3.setText(">>"); jButton3.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton3ActionPerformed(evt); } }); jButton4.setText(">|"); jButton4.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jButton4ActionPerformed(evt); } }); javax.swing.GroupLayout layout = new javax.swing.GroupLayout (getContentPane()); getContentPane().setLayout(layout); layout.setHorizontalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 434, Short.MAX_VALUE) .addGroup(layout.createSequentialGroup() .addComponent(jButton1) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton2) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton3) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jButton4))) .addContainerGap()) ); layout.setVerticalGroup( layout.createParallelGroup( javax.swing.GroupLayout.Alignment.LEADING) .addGroup(layout.createSequentialGroup() .addContainerGap() .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 84, Short.MAX_VALUE) .addPreferredGap( javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(layout.createParallelGroup( javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(jButton1) .addComponent(jButton2) .addComponent(jButton3) .addComponent(jButton4)) .addContainerGap()) ); pack(); }// </editor-fold>//GEN-END:initComponents private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed jTable1.getSelectionModel().setSelectionInterval(0, 0); updateButton(); }//GEN-LAST:event_jButton1ActionPerformed private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed int curRow = jTable1.getSelectedRow() - 1; jTable1.getSelectionModel().setSelectionInterval(curRow, curRow); updateButton(); }//GEN-LAST:event_jButton2ActionPerformed private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed int curRow = jTable1.getSelectedRow() + 1; jTable1.getSelectionModel().setSelectionInterval(curRow, curRow); updateButton(); }//GEN-LAST:event_jButton3ActionPerformed private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed jTable1.getSelectionModel().setSelectionInterval(jTable1.getRowCount() - 1, jTable1.getRowCount() - 1); updateButton(); }//GEN-LAST:event_jButton4ActionPerformed private void jTable1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseClicked updateButton(); }//GEN-LAST:event_jTable1MouseClicked private void jTable1MouseDragged(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTable1MouseDragged updateButton(); }//GEN-LAST:event_jTable1MouseDragged private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased updateButton(); }//GEN-LAST:event_jTable1KeyReleased /** * @param args the command line arguments */ public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { new Scroller().setVisible(true); } }); } // Variables declaration - do not modify//GEN-BEGIN:variables public javax.swing.JButton jButton1; public javax.swing.JButton jButton2; public javax.swing.JButton jButton3; public javax.swing.JButton jButton4; public javax.swing.JScrollPane jScrollPane1; public javax.swing.JTable jTable1; // End of variables declaration//GEN-END:variables private void updateButton() { jButton1.setEnabled(false); jButton2.setEnabled(false); jButton3.setEnabled(false); jButton4.setEnabled(false); if (jTable1.getSelectedRow() > 0) { jButton1.setEnabled(true); jButton2.setEnabled(true); } if (jTable1.getSelectedRow() < jTable1.getRowCount() - 1) { jButton3.setEnabled(true); jButton4.setEnabled(true); } Point p = new Point(0, jTable1.getSelectedRow() * jTable1.getRowHeight() > 0 ? jTable1.getSelectedRow() * jTable1.getRowHeight() : 0); jScrollPane1.getViewport().setViewPosition(p); jScrollPane1.updateUI(); } } 2008/3/12, Null Pointer <[EMAIL PROTECTED]>: > > alo juger's nanya donk > mis g ada jtable yg berisi ratusan data, nah gimana yach buat dia otomatis > scroll kalo g tekan tombol navigasi sedangkan row di jtable sudah tidak > nampak lagi. > > > > > > thx > > ------------------------------ > Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it > now.<http://us.rd.yahoo.com/evt=51733/*http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ> > > > -- ~~~~~~~~~~~~~~~~~~~~~~~~~ Dari M. Jumari, ST. Software Engineer PT. Gamatechno Indonesia Jl. Cik Ditiro 34 Yogyakarta 55223 Mobile: +622743251763 +6281904091661 Home: +628562899563 Web: http://mr.kazao.net Visit my blog @ http://blog.kazao.net --------------------------------------------------