Results 1 to 8 of 8
Thread: Button is sometimes truncated
- 06-02-2010, 11:17 PM #1
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
Button is sometimes truncated
What might be the reason that the button sometimes gets truncated? In the normal case, the button Cancel is big enough to have the whole word 'Cancel' spelled out, but on some machines, maybe the reslution is set different, the cancel button is smaller, only the text 'Can...' is visible.
Anybody know how I can fix that? Thanks!
-
Is this Swing? AWT? SWT? Other?
If Swing, you may need to look into how you are laying out your components in their containers. Have you gone through the Sun Swing layout tutorials? If not you will want to do so. Google: Java Swing Laying out Components within Container tutorial
first hit.
Much luck!
- 06-03-2010, 12:17 AM #3
Yea it did that for me as well when I used the BoxLayout. The truncation went away after I added a rigid area between the two buttons.
Like Fubarable said, it depends on the situation. Sometimes the layout can't use ur preferredSize (if you didn't do setPreferredSize(Dimension d), then it is an easy fix. All you have to do is button.setPreferredSize(new Dimension(width, height)); ) because it can't fit the button or w/e the reason might be. setMinimum() and setMaximum() might help."Experience is what you get when you don't get what you want" (Dan Stanford)
"Rise and rise again until lambs become lions" (Robin Hood)
- 06-03-2010, 05:05 PM #4
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
I use gridBagLayout.
Following are code for the buttons.
Java Code:/* * Define Cancel and OK buttons */ cancelButton = new TButton(); cancelButton.setText("Cancel"); cancelButton.setPreferredSize(new Dimension(65, 23)); okButton = new TButton(); okButton.setText("OK"); okButton.setPreferredSize(new Dimension(65, 23)); /* * OK button */ GridBagConstraints gridBagConstraints = new GridBagConstraints( // OK Button 60, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0); buttonPanel.add(okButton, gridBagConstraints); /* * Cancel button */ GridBagConstraints gridBagConstraints_1 = new GridBagConstraints( // Cancel Button 70, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 10), 0, 0); buttonPanel.add(cancelButton, gridBagConstraints_1);
- 06-03-2010, 06:10 PM #5
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
I also noticed that after I change the display setting (resolution) of my PC, the Cancel button and OK button behaves differently. The width of the OK button changes when I resize the screen. While the Cancel button's size stays the same no matter how small I resize the screen. Why are they behaving differently? How can I make the Cancel button hehave the same as the OK button?
-
Don't use setPreferredSize for the JButtons but rather let the JVM determine what would in fact be the preferred size for the buttons, otherwise your preferred size might run counter to what the current OS and video set up allows for the button text and your button may be too small to hold all the text.
- 06-04-2010, 06:50 AM #7
Also note that you don't need a new GridBagConstraints object for each component you add to the GridBagLayout. And why on earth are your gridx values 60 and 70? Does your layout have that many columns? Note that the gridx and gridy values are NOT pixel coordinates.
Recommended reading: How to Use GridBagLayout (The Java™ Tutorials > Creating a GUI With JFC/Swing > Laying Out Components Within a Container)
And as already mentioned, DON'T setPreferredSize.
db
- 06-07-2010, 05:36 PM #8
Member
- Join Date
- Aug 2009
- Posts
- 60
- Rep Power
- 0
Similar Threads
-
Button Glitch
By dunafrothint in forum AWT / SwingReplies: 4Last Post: 02-16-2010, 04:06 PM -
Button
By Tb0h in forum New To JavaReplies: 6Last Post: 07-22-2009, 01:28 AM -
Problem with Socket Client - Intermittent Truncated Response in AIX
By cheongww in forum NetworkingReplies: 4Last Post: 10-02-2008, 06:32 PM -
Using SWT Button
By Java Tip in forum Java TipReplies: 0Last Post: 01-08-2008, 09:05 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks