something tricky with JTextFields

Hello everyone!

Here's the problem:

Is there a possibility in getting some number of JTextFields depending from database column cell count?

For example- in *.mdb database i have one column with 5 rows and some data! So this number of rows is determing JTextField count which show up on JPanel filled with data from database!

Tnx!

[364 byte] By [kode128a] at [2007-11-26 20:37:09]
# 1

Declare:

Vector<JTextField> vector = new Vector<JTextField>();

then parse the database. Every time you have a row

vector.add(new JTextField())

then in gui building part you just:

for (int i=0;i<vector.size();i++{

panel.add(vector.get(i));

}

as simple as that>

hellbindera at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 2
Should I point out the dangers of parsing database results and building UI components in the same thread? :o)
itchyscratchya at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 3
@itchybe my guest :-)
hellbindera at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 4
I think I was directing the question more at myself in terms of "can I be bothered?" ;o)
itchyscratchya at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 5
Use a JTable as a generic solution. It will handle any number of columns and rows: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=5123381&start=1
camickra at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 6
Hello again, question is: how can i parse the database? Couldn't find any example here or i was just looking not in the right place....!Tnx
kode128a at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 7
Hello camickr! I tried this variant before even i posted this subject, but didn't suceeded in making this to work!:( Tnx anyway for advice
kode128a at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...
# 8

Connection con = DriverManager.getConnection

( "jdbc:myDriver:wombat", "myLogin","myPassword");

Statement stmt = con.createStatement();

ResultSet rs = stmt.executeQuery("SELECT a, b, c FROM Table1");

while (rs.next()) {

int x = rs.getInt("a");

String s = rs.getString("b");

float f = rs.getFloat("c");

vector.add(new JTextField());

}

skeleton taken from:

http://java.sun.com/docs/books/tutorial/jdbc/overview/index.html

Message was edited by:

hellbinder

hellbindera at 2007-7-10 1:31:03 > top of Java-index,Desktop,Core GUI APIs...