Results 1 to 2 of 2
  1. #1
    Allgorythm is offline Member
    Join Date
    Dec 2009
    Posts
    20
    Rep Power
    0

    Default how to implement simply a progress bar

    i want to see the progress of searching the value in my table, but I dont have any idea how. what im thinking now is maybe there is something to do with threads. i dont know anything about threads its too far from what i learned now. pleas help me with this one.
    Java Code:
    public class ProgressSample extends JFrame {
        
        public ProgressSample() {
    
            ProgressBar monitor = new ProgressBar();
            JPanel panel = new JPanel();
            final JTextField searchField = new JTextField();
            panel.setLayout(null);
    
            final String[] columns = {"Name", "Surname", "Age"};
    
            Object[][] values = {{"Jhon", "Java", "23"}, {"Stupid", "Stupido", "500"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Michael", "Winnie", "20"}, {"Winnie", "Thepoor", "23"},
                                    {"Max", "Dumbass", "10"}, {"Melanie", "Martin", "500"},
                                    {"Jollibe", "Mcdonalds", "15"}};
    
            final JTable mainTable = new JTable(values, columns);
            
            mainTable.setColumnSelectionAllowed(true);
            mainTable.setRowSelectionAllowed(true);
    
            JScrollPane scroll = new JScrollPane(mainTable);
            scroll.setBounds(0, 100, 900, 500);
    
            searchField.setBounds(10, 50, 150, 20);
            searchField.addActionListener(new ActionListener() {
    
                public void actionPerformed(ActionEvent e) {
    
                    // set the column selection to false to gain multiple row selection
                    mainTable.setColumnSelectionAllowed(false);
    
                    // clear the selection for the next search, so the table wont
                    // be flooded by selection highlight.
                    mainTable.clearSelection();
    
                    String value = searchField.getText();
    
                    for (int row = 0; row <= mainTable.getRowCount() - 1; row++) {
    
                        for (int col = 0; col <= mainTable.getColumnCount() - 1; col++) {
    
                            if (value.equals(mainTable.getValueAt(row, col))) {
    
                                // this will automatically set the view of the scroll in the location of the value
                                mainTable.scrollRectToVisible(mainTable.getCellRect(row, col, true));
    
                                // this will automatically set the focus of the searched/selected row/value
                                mainTable.addRowSelectionInterval(row, row);
                            }
                        }
                    }
                }
            });
    
            monitor.setBounds(300, 50, 200, 20);
    
            panel.add(monitor);
            panel.add(searchField);
            panel.add(scroll);
    
            getContentPane().add(panel);
    
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setSize(906, 700);
            setLocationRelativeTo(null);
            setVisible(true);
        }
    
    
        public static void main(String[] args) {
    
        
                    new ProgressSample();
              
        }
    }

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,947
    Rep Power
    19

Similar Threads

  1. How to simply get if a key is pushed?
    By ChazZeromus in forum New To Java
    Replies: 6
    Last Post: 07-28-2009, 01:32 AM
  2. It simply won't sort
    By xf021209 in forum New To Java
    Replies: 7
    Last Post: 04-25-2009, 03:53 PM
  3. input to an integer (simply)
    By chitwood in forum Advanced Java
    Replies: 3
    Last Post: 03-18-2009, 06:34 AM
  4. Error With Simply Displaying Picture
    By JDCAce in forum Java Applets
    Replies: 4
    Last Post: 10-07-2008, 08:09 PM
  5. how to implement progress bar .....
    By roshithmca in forum AWT / Swing
    Replies: 1
    Last Post: 03-06-2008, 04:18 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •