Not signed in (Sign In)

Vanilla 1.1.4 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoradmin
    • CommentTimeFeb 28th 2008
     
    The forum is for discussing problems/suggestions related to Project 5
    • CommentAuthortdgray
    • CommentTimeMar 11th 2008
     
    The base class for this is in the folder /Data/examples/windows/ from the CD and the source file is Choosers.java so you don't have to look too hard for it. The CD was posted in the general collaboration forum if anyone hadn't seen that.
    • CommentAuthorjmscott2
    • CommentTimeMar 12th 2008
     
    Does the font need to increase by 10pt every time it is changed?

    I get the name of the font as a string called fontName from my JOptionPane. Then I change the font with
    setFont( new Font( fontName, Font.PLAIN, 16));

    Since I have to give the Font constructor a size, do I also need to increase by 10 each time?
    • CommentAuthoradmin
    • CommentTimeMar 13th 2008
     
    I looked into that when I created the project. Mine does increase the font by 10 points each time. It is much more problematic to create it so that the font adds 10 points to the default size, since the method I used just takes the current size and adds 10 points. The first time through, that adds 10 points to the default size. The next time through, it adds 10 to the current size, and so forth. To keep it simple, you can do it that way. If you want to try to come up with a way just to add 10 points to the original size, that's fine to, but not a requirement.
    • CommentAuthoradmin
    • CommentTimeMar 13th 2008
     
    Further clarification: The routine I used just grabs the font and doesn't designate a size. Therefore, the default size is selected, and I add 10 points to that (since the default sizes tend to be small). If you want to create yours so that you pass it a size to begin with, just pass it a size of 14 and call it good. No need to add 10 ... I just did that so that the default size wouldn't be used.
    • CommentAuthortdgray
    • CommentTimeMar 13th 2008
     
    When I used the default size from a selected font, it was so small the text wasn't really visible. After adding 10, it was at least visible. However in most cases it appeared SMALLER than the text was after opening the file initially. That had me tripped up at first, because I was expecting it to be larger than the original text appeared. But apparently from how I understand the previous post this would still be acceptable?
    • CommentAuthorjmscott2
    • CommentTimeMar 14th 2008
     
    I think we can either add 10 to the default size, or set the font size at 14... i don't know off the top of my head but i'd assume there is a setFontSize method of some kind...
  1.  
    All right, I'm a little confused about one thing: am I supposed to build my own Font Chooser that resembles what is posted, or is there a FontChooser class available in the java package? I've checked online and the only font chooser classes that I can find don't resemble anything like what is displayed on the web site, so I'm assuming I have to build it myself. If someone could clarify this for me, I'd really appreciate it, it'd be a shame for me to have started building something that I didn't need to spend time on in the first place.
    • CommentAuthoradmin
    • CommentTimeMar 15th 2008
     
    You'll have to build your own (look at the hint in the assignment in the text).
    • CommentAuthordtran
    • CommentTimeMar 15th 2008
     
    JScrollPane scrollListing = new JScrollPane( fontFamily );

    I want to put all of my font listing on a scroll pane, however, this line of code tells me it is incorrect. Any ideas as to why this line of code is wrong?
    • CommentAuthorcdstreit
    • CommentTimeMar 15th 2008
     
    Danny what type of object is fontFamily? Its been awhile since I have played with scrollpanes so this might not be 100% correct but I think they can only have other componets added to them.
  2.  
    Danny, if i remember my research for this project correctly a component such as a ComboBox is what is added to the JScrollPane. I'm interested to see your solution that your working on for this, however there is a much easier method(of the JOptionPane) for doing what you are doing that is handled completely by the JOptionPane class. The JOptionPane class has specific look-and-feel code that adds components to the JOptionPane and even determines the layout automatically. Of course there are numerous ways of solving this problem, using the JOptionPane approach utilizes past programming efforts to make your programming quicker and more efficient (which is the fun of Object oriented programming)
    • CommentAuthordtran
    • CommentTimeMar 16th 2008
     
    My gut instinct told me to create a Jlist of all the fonts and place them in a Jscrollpane. Once I created the scroll object, i decided to insert it into the joptionpane. after some research on joptionpane, i was able to create almost exactly like prof. garrett's joptionpane. Chris, I was able to figure out the fontFamily situation, the solution was quite simple. Micheal, I probably approach the problem the hardest possible way. Could you tell me the easier solution to this problem?
    • CommentAuthorjastout
    • CommentTimeMar 16th 2008
     
    one thing that helped me a lot with project 5 was this website. it basically helps with JOptionPane.
    http://java.sun.com/developer/JDCTechTips/2004/tt0122.html#1
    especially the example that looks exactly like the picture on the Dr. Garrett's website.
    • CommentAuthorjmscott2
    • CommentTimeMar 16th 2008
     
    If you use JOptionPane.showInputDialog() it will basically build the chooser for you.

    There is an example of this at http://java.sun.com/docs/books/tutorial/uiswing/components/dialog.html
    • CommentAuthortdgray
    • CommentTimeMar 16th 2008
     
    I started out making the program the same way D-Tran did, it was not very fun. After getting a little frustrated, I opened the book to read the actual problem and it says:

    "Swing currently has no font chooser class, so create your own using a JOptionPane object to display a list of fonts from which the user can select"

    I'm glad I'm not the only one who doesn't like to open this book!
  3.  
    Danny, when I first started this project, my first reaction was that I was going to have to spend a lot of time creating this font chooser myself piecemeal from different components like a ComboBox or ScrollPanel and a combination of others. However, upon researching further into the JOptionPane class, and learning about its many different methods and capabilities, this project got a lot easer. At first I thought I would have to have a lot of code in order to add various components to the JOptionPane object I would be using, but after reading about the class thoroughly, I discovered that the JOptionPane class already has specific code and methods within it to add components automatically. Like Jenny said, the showInputDialog() method various parameters you can use in order to create a simple yet unique dialog box. This is your starting point, the rest is up to you...