#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    50
    Rep Power
    11

    problems with AWT/Swing buttons


    Hello! I have a problem with GUI button, I have a multiple button in a form, each button has a different label. How can I make them uniform in length? Is there a way to set the button length? My second problem is with button with 2-word label on it, for example, if I have a button with label "Submit Query", how can I make "Query" go to the next line? Please help me, thanks guys in advance
  2. #2
  3. No Profile Picture
    Clueless llama
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Feb 2001
    Location
    Lincoln, NE. USA
    Posts
    2,353
    Rep Power
    117
    For the size, try setPreferredSize(). Some layout managers (FlowLayout I think) will over ride this bahavior I believe, so try another layout manager if it doesn't work.

    As for the multi-line button, I am not sure, You may have to look at the code in the Button class that prints the text and override that code to do what you want.
  4. #3
  5. I played Richard the Third
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Den Haag, Netherlands
    Posts
    122
    Rep Power
    11
    Nemi is right regarding the disrespect some layoutmanagers have for their components size.
    The best advise is to experiment with different layoutoutmanagers in combination with setPerefferedSize() and see what they do with it. I know for a fact that Border- and GridLayout ignore the component size, but i thought FlowLayout did not ignore it.

    Regarding the second problem, there is an easy solution, if you're using java 1.3 or up with swing. A swing-JButton can have a label/caption with HTML-formatting

    try the following:

    JButton htmlButton = new JButton("<HTML> Submit <BR> Query </HTML>");

    you can use lots of the more basic HTML-tags, including tables. Works too for the JLabel and the tooltiptext.


    Succes
    Now is the winter of our discontent made glorious summer by this son of York.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Posts
    50
    Rep Power
    11
    Thanks Nemi, thanks Targaz, for your reply, I'm really a new with Java, how will I use SetPreferredSize()? If possible, can you give a short code using SetPreferredSize? I used HTML tags for the JButton, it works perfectly, thank you very much
  8. #5
  9. I played Richard the Third
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2003
    Location
    Den Haag, Netherlands
    Posts
    122
    Rep Power
    11
    something like this ?


    int h = 30;
    int w = 100;


    Dimension d = new Dimension(w,h); // in java.awt.*

    JButton button = new JButton("blah");

    button.setPrefferedSize(d);

    JPanel p = new JPanel(new FlowLayout());
    p.add(button);
    Now is the winter of our discontent made glorious summer by this son of York.

IMN logo majestic logo threadwatch logo seochat tools logo