Is there a way for Java to determine the size/dimensions of the command-line console it's running in? [duplicate]
Possible Duplicate:
Can I find开发者_JAVA技巧 the console width with Java?
For example, when you run nano at the Linux command line, it automatically resizes its text formatting to fit the display dimensions, even as you change them on the fly.
I know it's a long shot, but is there a way for Java to do detect display size and changes made to it?
You would need to use JNI to call ncurses or use a library that does the same.
If all you need is to get dimension information, there's an example here that has API calls to getRowCount and getColumnCount.
You can get the dimensions of the window that a Swing application is running in by calling getSize on the JFrame or whatever the outer container is. That's what I'd use for something like you describe: get the window size, then calculate the font size to be some percentage of the window size, probably with upper and lower bounds so you don't set a font size of 2 when the user shrinks the window or 150 when they grow it.
You can call GraphicsConfiguration.getLocalGraphicsConfiguration to get an object that gives you information about the graphics environment in general. You might want to check the Java Docs on that class to see if it gives the sort of information you want. getMaximumWindowBounds might be what you're looking for.
You can also maximize a window with setExtendedState, and then you could check the bounds at that time.
精彩评论