Results 1 to 2 of 2
- 02-19-2010, 06:59 AM #1
Member
- Join Date
- Dec 2009
- Posts
- 20
- Rep Power
- 0
Problems with calling a ProgressBar dialog in another class
hi, I dont know why does my progressBar dialog doesnt appear correctly as I want.
the frame does appear but the container is transparent, i cant see the progress bar ,i cant figure a way how to solve this problem.
how can i make a progressBar dialog outside my class that i can call with no problems like this? i tried to search at google but i cant understand most of it so i decide to post my question here.
Java Code:public class TableSample extends JFrame { private JTextField searchField; private JTable table; private JPanel panel; private JScrollPane scroll; public TableSample() { panel = new JPanel(); searchField = new JTextField(); panel.setLayout(null); final String[] columns = {"Name", "Surname", "Age"}; final Object[][] names = {{"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"}}; table = new JTable(names, columns); table.setColumnSelectionAllowed(true); table.setRowSelectionAllowed(true); scroll = new JScrollPane(table); scroll.setBounds(0, 100, 900, 500); searchField.setBounds(10, 50, 150, 20); searchField.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { new ProgressBar(); // set the column selection to false to gain multiple row selection table.setColumnSelectionAllowed(false); // clear the selection for the next search, so the table wont // be flooded by selection highlight. table.clearSelection(); String value = searchField.getText(); for (int row = 0; row <= table.getRowCount() - 1; row++) { for (int col = 0; col <= table.getColumnCount() - 1; col++) { if (value.equals(table.getValueAt(row, col))) { // this will automatically set the view of the scroll in the location of the value table.scrollRectToVisible(table.getCellRect(row, col, true)); // this will automatically set the focus of the searched/selected row/value table.addRowSelectionInterval(row, row); for (int i = 0; i <= table.getColumnCount() - 1; i++) { //table.getColumnModel().getColumn(i).setCellRenderer(new SingleAndMultipleRowSelectionRenderer()); } } } } } }); 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 TableSample(); } }
the progressbarJava Code:import java.awt.BorderLayout; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JProgressBar; public class ProgressBar { JDialog dialog; JProgressBar progressBar; public ProgressBar() { dialog = new JDialog(new JFrame(), "Progress Dialog", true); progressBar = new JProgressBar(0, 500); dialog.add(BorderLayout.CENTER, progressBar); dialog.setSize(300, 75); dialog.setLocationRelativeTo(null); Thread t = new Thread(new Runnable() { public void run() { dialog.setVisible(true); } }); t.start(); for (int i = 0; i <= 500; i++) { progressBar.setValue(i); try { Thread.sleep(2); } catch (InterruptedException e) { e.printStackTrace(); } } } }
- 02-19-2010, 10:35 AM #2
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
Similar Threads
-
Child-Class Calling a Method in a Parent-Class
By Blah_ in forum New To JavaReplies: 5Last Post: 09-29-2009, 02:48 AM -
problems with progressbar
By komunista88 in forum Threads and SynchronizationReplies: 1Last Post: 01-05-2009, 09:02 PM -
problem calling function from class to class
By alin_ms in forum New To JavaReplies: 3Last Post: 12-19-2008, 07:35 PM -
Calling a method on original class from created class
By kpedersen in forum Advanced JavaReplies: 4Last Post: 08-20-2008, 12:25 AM -
Problems with readLine() and calling methods
By peachyco in forum New To JavaReplies: 2Last Post: 11-24-2007, 07:44 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks