![]() |
GUI Scrollbar Problem
Following the examples in my book, the code I have should place a scrollbar on the right side of the bottom most text area. Am I overlooking something?
Code:
CS1337.502 |
It probably does. There's nothing in the List right now to show, so the scrollbars are not necessary and the default policy is to only show them as needed.
If you want to add them in for all the time, add the two arguments to the JScrollPane constructor: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS. |
I would need a String array to store and display the names as they are added by the user, correct?
How do I clear all the text boxes? I want this to be one of the actions that take place when the save button is pressed. |
No, you're in a graphical environment, so I wouldn't recommend the use of a scanner.
The easiest thing to do is implement ActionListener onto contactBook. This way it can access any of the members. The textfields will need to be promoted to object members to retrieve them, but all you need to do is pull the fields, and insert into list. Now list is scalar in a sense, so it will only hold one object to display at a time, and not multiple fields in a single entry. I still haven't installed javac since I put in a new harddisk, but that would be as so: PHP Code:
If you want to show each in separate columns, you'll want to use a JTable instead of a JList. You can also create a Contact class and override the toString to show in the JList as you like, or rewrite the ListCellRenderer to change the display. Hmm, as interesting as that is, its possible to make it look like a JTable within the renderer, but I've never tried that before. |
I edited my last question while you were answering what was previously there. I figured it out and went the route of making private specific instances and then used getText().
how do I clear the JTextFields? I wish to include this as one of the actions that happen when the save button is pressed. |
Simply call the .setText and set it to "".
|
Where can I put output.close() so I won't get any errors? Right now I have it inside the try block, but that causes the file content to be erased and then written over that. (So all of the data isn't in the output file, just the latest entries.)
Code:
import java.util.Scanner; |
The try block won't cause the overwrite. Its the print that's doing that. Close shouldn't throw an error in the PrintWriter; only the constructor is mandated to do that.
Move all file handling into a try block. Use only a member to declare the path to it; File() may throw an error as well. Switch it to the FileWriter class as this makes appending easier: PHP Code:
|
I'm gonna try playing with it to see if I can get anywhere. This material seems new to me.
Edit. I got it to work implementing your suggestions. Again, I sincerely thank you for your time and help. Code:
|
| All times are GMT +1. The time now is 07:01 PM. |
Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.