Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-12-2007, 07:23 AM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
3 Questions
Hi All,

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?

Regards,
Hiranya
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 11-12-2007, 08:23 AM
Member
 
Join Date: Oct 2007
Posts: 21
unhurt is on a distinguished road
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
Code:
JTextArea myTextArea = new JTextArea(); JScrollPane jsp = new JScrollPane(myTextArea);
this is a light component this way u got to implement a line wrap on it or u can go for the heavier component

Code:
JTextPane myTextPane = new JTextPane(); JScrollPane jsp = new JScrollPane(myTextPane);
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
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

Last edited by unhurt : 11-12-2007 at 08:29 AM.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 11-12-2007, 01:53 PM
Member
 
Join Date: Jun 2007
Location: Colombo, Sri Lanka
Posts: 32
hiranya is on a distinguished road
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?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 11-14-2007, 05:44 AM
Member
 
Join Date: Oct 2007
Posts: 21
unhurt is on a distinguished road
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
JDBC-ODBC

Code:
Ps = Con.prepareStatement(SSQL); Rs = Ps.executeQuery(); while(Rs.next()) { dataModel.addRow(new Object[]{(Rs.getString("name")), (Rs.getString("studentID")), (Rs.getString("courseID"))}); }
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
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...
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 11-14-2007, 06:57 AM
Member
 
Join Date: Oct 2007
Posts: 21
unhurt is on a distinguished road
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


Code:
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
this is from Comparing Dates (Java Developers Almanac Example)


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 ^^....

Last edited by unhurt : 11-14-2007 at 07:04 AM.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Stuck on Two Questions, Please Help sylo18 New To Java 5 03-11-2008 03:03 AM
2 simple java questions jimJohnson New To Java 2 02-02-2008 11:35 AM
Just a Few Questions pringle New To Java 21 01-09-2008 08:21 PM
few java questions hiaslpix New To Java 4 01-01-2008 07:47 AM
questions Gilgamesh New To Java 3 11-28-2007 01:18 AM


All times are GMT +3. The time now is 02:27 PM.


VBulletin, Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org