I got three questions this time.
1. I have two strings both containing date values (of the form yyyy-mm-dd). How do I compare these two dates and pick the earlier date?
2. I have a JTextField with a fairly large width (large enough to accommodate multiple lines of text). When the user types in a lengthy string of text it should appear in multiple lines in the text field. How do I achieve this behaviour? (Now when the user types in a long string it all goes into one line and the user has to scroll sideways to see the entire line)
3. Is there an easier way to bind a JTable to a table in a database?
1. u can compare them like any normal int value by using the > and < sign as long as they are still in the date form(not string, int)
2. u got to use
this is a light component this way u got to implement a line wrap on it or u can go for the heavier component
JTextArea myTextArea = new JTextArea();
JScrollPane jsp = new JScrollPane(myTextArea);
this is the heavier component, u don't have to implement a line wrap on it but if u want to customize it and stuff this is the one u want to go for
JTextPane myTextPane = new JTextPane();
JScrollPane jsp = new JScrollPane(myTextPane);
add ur jsp to ur frame not ur myTextArea/myTextPane like how u do with ur JTextfield
i suggest u try both and know whats the different
3. to bind? well i don't know about what u mean but im guessing to load data from database to JTable? u got to specify each column what field u want to field it up with from ur database
Thanks for the help...
Regarding the third question, for the moment I'm reading the table contents from the database into a multidimensional array and then use the array as the data source of the JTable. Is this the correct way of doing this? If not how?
well u can cut the part of adding into the multidimensional array by doing this
but i don't know how u access ur database, my way is through the
ofcourse it must also include some try catch line, so i explain abit here... prepare the SQL statement then execute it... so while loop will go through the database record till no more found
Ps = Con.prepareStatement(SSQL);
Rs = Ps.executeQuery();
datamodel is for the JTable new object will declare new record being append to the end so name, studentID, courseID are my database field name it will get the record from there and will fill up ur JTable bcz of the while loop
the code above is incomplete, i didn't include my declaration of my JDBC and variable declaration so if u know how to do then i think u know where to put it, else ill give u the complete 1 when u ask for...
hey im sory about part 1.... kinda thought that it would work since it work for me in VB.NET but anyway here is the right one i think u can try
this is from Comparing Dates (Java Developers Almanac Example)
Calendar xmas = new GregorianCalendar(1998, Calendar.DECEMBER, 25);
Calendar newyears = new GregorianCalendar(1999, Calendar.JANUARY, 1);
// Determine which is earlier
boolean b = xmas.after(newyears); // false
b = xmas.before(newyears); // true
for ur part 1, u need to make it string to date format... there is a thread on this here but the output gives me some weird number after the date. come to worse... change all to int lol... and arrange them to be compare by year-month-day(20071131 > 20061131) format lol, i know its kinda incorrect.... but anyway i think for proper format is the simpledateformat, do post ur solution when u found out how... i want to know too ^^....