Page 2 of 2 FirstFirst 12
Results 21 to 27 of 27
  1. #21
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Thankyou very much. For the size, I set the preffered size, size, minimum size, and maximum size all to the same thing and that seems to work. Probably unnecessary, but If i just use size or preffered it gives weird results.
    For the package Q: I'll leave the way I've packages as it is then.
    L&F: I'll try and experiment then.
    JFrame: I did understand that you meant all methods are static, not the class, but you gave me a better understanding of how it is put together.
    Extending JPanel: Ok, I understand now. I will use this method for my panels too.
    Nevermind about other responses you gave that I didn't comment on again here.
    Thanks again, but you left out the one question, the one about should I declare my swing controls in fields or in local variables in the constructor because I've seen you do both in your example. NetBeans make fields.. Ya could yoou answer that one when you get a chance? ty
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  2. #22
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    Just like any Java variable, I try to make my Swing controls local when I can, and fields if I have to. It all goes towards exposing only the information that is absolutely necessary to expose and no more -- to hide the rest if possible.

    For instance in the CardWorkPanel class, I need to get the selected item from both JComboBoxes, and so both are made class fields. The comboPanel JPanel which holds them however will never need to reveal its state or behaviors, and so I keep this component local. Same for most all JLabels (except for a label whose text changes during the program run).
    Last edited by Fubarable; 02-11-2009 at 05:00 AM.

  3. #23
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Ok thanks very much. If I have no more questions by tomorrow I will [SOLVED] this thread.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  4. #24
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    Just to clear that answer up, So if the control is used in a method in the class, or an event method, it must be a field? I'm not sure about if it needs to be a field or not when it has an event method. I'm pretty sure it has to be field to be used in normal methods, but event methods don't refer to the control in them do they? In the constructor adding listeners you tell which method to call.. thnx.
    EDIT: When I try to add a JButton, It takes up the entire Panel. I have checked generated code and done same thing. I added event listener and method, tried local variable and field to contain the button, and it still takes up the entire screen. I got the Look And Feel to work fine, but this won't work. I tried setting size, and prefferred size, and it did nothing. I don't want to have to set size each time anyway if that did make it work, Hoe do I make it have default size, Big enough to contain the text and no more?
    Last edited by MK12; 02-12-2009 at 01:19 AM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  5. #25
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    My thread has fallen down the list probably farther then you look because I asked this a while ago. Can someone please answer the question above? thanks
    Last edited by MK12; 02-13-2009 at 02:59 AM.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

  6. #26
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

    Default

    So if the control is used in a method in the class, or an event method, it must be a field? I'm not sure about if it needs to be a field or not when it has an event method. I'm pretty sure it has to be field to be used in normal methods, but event methods don't refer to the control in them do they? In the constructor adding listeners you tell which method to call..
    Not sure exactly what you are asking, but a general answer again is, you declare variables to be as local as possible or in other words to have as limited a scope as possible. If you have a specific concern on this, you may do well to post a small bit of example code.

    When I try to add a JButton, It takes up the entire Panel. I have checked generated code and done same thing. I added event listener and method, tried local variable and field to contain the button, and it still takes up the entire screen. I got the Look And Feel to work fine, but this won't work. I tried setting size, and prefferred size, and it did nothing. I don't want to have to set size each time anyway if that did make it work, Hoe do I make it have default size, Big enough to contain the text and no more?
    Layout managers are the key here. What layout manager is being used by the container that accepts the button? Is it BorderLayout? And if so, are you specifying how you want the button added: BorderLayout.NORTH, BorderLayout.SOUTH, etc... Or do you need to place the button in its own JPanel (which uses FlowLayout by default) and then add that to the holding container as noted above? Have you gone through the layout manager tutorial? If so, you may wish to re-review it as it contains some valuable nuggets of information.

  7. #27
    MK12's Avatar
    MK12 is offline Senior Member
    Join Date
    Jan 2009
    Posts
    185
    Rep Power
    6

    Default

    .. Ok thanks, I haven't got to layout manager part yet. I think I get the limiting scope thing now. thanks. SOLVED.
    Tell me if you want a cool Java logo avatar like mine and I'll make you one.

Page 2 of 2 FirstFirst 12

Similar Threads

  1. ResultSet size
    By bugger in forum JDBC
    Replies: 18
    Last Post: 06-25-2011, 09:36 PM
  2. File size
    By eva in forum New To Java
    Replies: 2
    Last Post: 12-19-2007, 10:27 AM
  3. Object size
    By kavithas in forum New To Java
    Replies: 0
    Last Post: 11-30-2007, 01:00 PM
  4. how to set an image size
    By valery in forum New To Java
    Replies: 1
    Last Post: 08-06-2007, 09:27 PM
  5. how to set the value of BUFFER SIZE
    By oregon in forum Advanced Java
    Replies: 1
    Last Post: 08-06-2007, 04:16 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •