Results 1 to 3 of 3
- 08-01-2008, 06:43 AM #1
Member
- Join Date
- Jun 2008
- Posts
- 7
- Rep Power
- 0
How can I set the frame's size flexible to show it's title(variable length) in full?
Hello,
I have a frame that has a table in it.
This frame has a title, something like,
"Find results for test.html - 3 item(s)"
And in the table, it shows 3 results.
My problem is that I don't know how long the frame's title will be. Sometimes it will be short like "Find results for test.html - 3 item(s)"
and sometimes it will be long like, "Find results for asdfdfdfdfdfsdfdfdfdf.html - 3 item(s)"
Currently, what I do is
It shows frame's title full in case of "Find results for test.html - 3 item(s)"Java Code:table.setPreferredScrollableViewportSize(new Dimension(500, 70)); table.setFillsViewportHeight(true);
but it doesn't show frame's title full for "Find results for asdfdfdfdfdfsdfdfdfdf.html - 3 item(s)"
How can I set the frame's size flexible to show it's title in full?
Thanks,
- 08-01-2008, 02:38 PM #2
Is the problem not knowing how wide in pixels the title is so that you can make the frame big enough to show ALL of the title?
I think the class FontMetrics has methods to get the width of a String.
- 08-01-2008, 02:58 PM #3
Member
- Join Date
- Jul 2008
- Posts
- 31
- Rep Power
- 0
You need to call a method after setting the title of the Frame. The one I supplied should work. However I think the user should decide if they want to resize the frame.
HTHJava Code:private static void fitFrameTitle(JFrame frame) { FontUIResource font = (FontUIResource) UIManager.get("InternalFrame.titleFont"); if (font != null) { int prefferedWidth = frame.getWidth(); int prefferedHeight = frame.getHeight(); FontMetrics fm = frame.getFontMetrics(font); Rectangle2D bnds = fm.getStringBounds(frame.getTitle(), frame.getGraphics()); prefferedWidth = (int) bnds.getWidth() + 50;//50 is space for the maximise and minimise buttons might need to increase this Dimension dimension = new Dimension(prefferedWidth, prefferedHeight); frame.setPreferredSize(dimension); frame.setMinimumSize(dimension); frame.pack(); } }
Stephen
Similar Threads
-
Demonstration of the variable length arguments
By Java Tip in forum java.langReplies: 0Last Post: 04-17-2008, 07:38 PM -
A generic framework for a flexible, multi-threaded server
By Java Tip in forum java.netReplies: 0Last Post: 04-07-2008, 08:14 PM -
bean with flexible version ability
By nineball in forum Advanced JavaReplies: 0Last Post: 03-26-2008, 09:59 AM -
netbeans 6.0 not show commpunent or show blank page
By fahimaamir in forum NetBeansReplies: 1Last Post: 01-26-2008, 06:20 AM -
Full screen
By Jack in forum Advanced JavaReplies: 2Last Post: 07-02-2007, 05:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks