Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search Coderanch
Advance search
Google search
Register / Login
Geoff Jefferson
Ranch Hand
+ Follow
news
102
Posts
22
Threads
since Apr 09, 2009
Merit badge:
grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads
Recent posts by Geoff Jefferson
add custom Jtable to GUI Builder How?
>> lso, there is a forum here at the Java Moose Saloon that can answer GUI questions
specifically, see the Swing forum for this.
Ooops, your already here. My apologies. I've been between forums and forgot where I was!
show more
14 years ago
Swing / AWT / SWT
add custom Jtable to GUI Builder How?
>> here is custom Table code but I want to add it in GUI Builder Netbeans. how can we do this.
If you want to add a JTable to your GUI in NetBeans you can do this from within the IDE.
There is a palette that enables you to add components there.
Also, there is a forum here at the Java Moose Saloon that can answer GUI questions
specifically, see the Swing forum for this.
G.
show more
14 years ago
Swing / AWT / SWT
Using one "actionPerformed" by class or one by component ?
Okay, why aren't my links working?
http://download.oracle.com/javase/tutorial/uiswing/events/intro.html
show more
14 years ago
Swing / AWT / SWT
Using one "actionPerformed" by class or one by component ?
My guess would be as many as you need base on what you want from
your component.
Take a look at:
http://download.oracle.com/javase/tutorial/uiswing/events/intro.html
G.
show more
14 years ago
Swing / AWT / SWT
GUI integration with code written
http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html
Sorry, this link should work.
G.
show more
14 years ago
Swing / AWT / SWT
GUI integration with code written
You have declared many members (variables).
Have you assigned anything to them?
Take a look at:
http://download.oracle.com/javase/tutorial/java/javaOO/classvars.html
G.
show more
14 years ago
Swing / AWT / SWT
Reading array from file
Awesome!
Thank you.
show more
14 years ago
I/O and Streams
Reading array from file
>> The body of the for loops does what?
That's where I'm having trouble. I can't figure out how to assign, or copy obj to a new array.
show more
14 years ago
I/O and Streams
Reading array from file
I cannot figure out how to copy array from ObjectInputStream beginning on line 95.
package tabledemo; import java.awt.BorderLayout; import java.io.EOFException; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.InvalidClassException; import java.io.NotSerializableException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.StreamCorruptedException; import java.util.Arrays; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class TableDemo { JTable table; private FileOutputStream fOut = null; private ObjectOutputStream oOs = null; private FileInputStream fIn = null; private ObjectInputStream oIS = null; private void save() { Object[][] array1 = new Object [table.getRowCount()][table.getColumnCount()]; for ( int i = 0; i < array1.length ; ++i) { for ( int j = 0; j < table.getColumnCount() ; ++j ) { array1[i][j] = table.getValueAt(i, j); System.out.println("save values are: " + array1[i][j] ); } } writeArrayToFile(array1, "C:\\Air\\HVACData"); } protected void writeArrayToFile( Object[][] array, String filePath ) { try { fOut = new FileOutputStream(filePath); oOs = new ObjectOutputStream(fOut); System.out.println("Array size is: " + array.length); for ( int i = 0; i < array.length; ++i) { for ( int j = 0; j < array[i].length; ++j ) { System.out.println("Value is: " + array[i][j]); } } oOs.writeObject(array); } catch(IndexOutOfBoundsException e) { System.out.println("IOBE "); } catch(IOException e) { System.out.println("IOE "); } finally { if (oOs != null){ try { oOs.close(); // fIn.close(); } catch (IOException e){ } } } } public Object[][] getData(){ Object[][] array = new Object [2][3]; Object obj = new Object(); try { fIn = new FileInputStream ("C:\\Air\\HVACData"); oIS = new ObjectInputStream(fIn); while (( obj = oIS.readObject()) != null) { System.out.println("Class is " + obj.getClass()); //[[Ljava.lang.Object; for ( int i = 0; i < array.length; ++i) { for ( int j = 0; j < array[i].length; ++j ) { // How do I obj back into an array? } } } } catch (EOFException evt) { System.out.println("EOF"); //evt.printStackTrace(); } catch (IllegalArgumentException evt) { System.out.println("IAE"); } catch (FileNotFoundException evt) { System.out.println("FNF Read Item File"); } catch (ClassNotFoundException evt) { System.out.println("CNF"); } catch(StreamCorruptedException evt){ System.out.println("SCE"); } catch(SecurityException evt){ System.out.println("SE"); } catch(NullPointerException evt){ System.out.println("NPE"); } catch (InvalidClassException evt) { System.out.println("ICE"); } catch (NotSerializableException evt) { System.out.println("NSE"); } catch (IOException evt) { System.out.println("IOE filename ReadItemFile.java "); //evt.printStackTrace(); } finally { if (fIn != null){ try { fIn.close(); } catch (IOException evt){ } } } return array; } // end getDate() private void createAndShowGUI() { Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" }, { "Row2-Column1", "Row2-Column2", "Row2-Column3" } }; Object columnNames[] = { "Column One", "Column Two", "Column Three" }; JFrame frame = new JFrame(); table = new JTable(rowData, columnNames); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); save(); getData(); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { TableDemo demo = new TableDemo(); demo.createAndShowGUI(); } }); } }
show more
14 years ago
I/O and Streams
JTable and getValueAt()
Thank you.
show more
14 years ago
Swing / AWT / SWT
JTable and getValueAt()
Why couldnt I cast it to string?
show more
14 years ago
Swing / AWT / SWT
JTable and getValueAt()
Please bear with me. Even though I got the results I was looking for in this example. I am still a little unclear
on what my output was someting like ... [Ljava.lang.Object;@1e0bc08
What is the a representation of the index of the array?
show more
14 years ago
Swing / AWT / SWT
JTable and getValueAt()
>> You're making things too complicated if that's what you assumed.
I do have a tendancy to make things more difficult.
I re-wrote the loop and everything is working as exected.
Thank you.
G.
show more
14 years ago
Swing / AWT / SWT
JTable and getValueAt()
...until now. When I use the array as an argument to a method and then us Object.toString()
I still get [Ljava.lang.Object;@e24e2a.
package tabledemo; import java.awt.BorderLayout; import javax.swing.JFrame; import javax.swing.JScrollPane; import javax.swing.JTable; public class TableDemo { JTable table; Object [][] array; private void readTableData() { array = new Object [table.getRowCount()] [table.getColumnCount()]; String string ; Object object = new Object(); for ( int i = 0; i < table.getRowCount() ; ++i) { for ( int j = 0; j < table.getColumnCount(); ++j) { array[i][j] = table.getValueAt(i, j); object = table.getValueAt(i,j); string = object.toString(); System.out.println("readTableData string is: " + string); // good here //System.out.println("readTableData array is: " + array[i][j]); } } } protected void copyArray( Object[][] list ) { for ( Object item : list ) { String string = item.toString(); System.out.println("WriteFile string is: " + string); // not so good here } } private void createAndShowGUI() { Object rowData[][] = { { "Row1-Column1", "Row1-Column2", "Row1-Column3" }, { "Row2-Column1", "Row2-Column2", "Row2-Column3" } }; Object columnNames[] = { "Column One", "Column Two", "Column Three" }; JFrame frame = new JFrame(); table = new JTable(rowData, columnNames); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JScrollPane scrollPane = new JScrollPane(table); frame.add(scrollPane, BorderLayout.CENTER); frame.setSize(300, 150); frame.setVisible(true); readTableData(); copyArray(array); } public static void main(String args[]) { java.awt.EventQueue.invokeLater(new Runnable() { public void run() { TableDemo demo = new TableDemo(); demo.createAndShowGUI(); } }); } }
show more
14 years ago
Swing / AWT / SWT
JTable and getValueAt()
Thanks Rob, your explantion solved my problem.
G.
show more
14 years ago
Swing / AWT / SWT