I am maintaining some existing Java code so I am not looking to make major changes to the way it is currently done. I removed some items from a dialog, (which is fundamentally an org.eclipse.swt.widgets.Shell) and now the dialog displays much smaller, so small that the title and the menu bar do not display in their entirety. I can set the minimum width to fix this problem, but since the users may have different screen sizes and resolutions, I would prefer not to attempt a one-size-fits-all width.
I set it to the preferred size, using
getShell().computeSize
and
.setSize
and it improved the situation (the menu displays completely), but the dialog title is still being elided.
Is there a way of determining the minimum width of a dialog to display the title completely?
Alternatively, is there a way of getting the title as it's displayed (including ellipsis, if any) or of determining if it's being elided?
IFAIK, there is no way to compute the exact size of a shell so that its title can always be shown unshortened.
While the width of a string can be computed with a graphics context like this:
GC gc = new GC(shell);
Point titleSize = gc.textExtent("title");
gc.dispose();
int titleWidth = titleSize.x;
there is no way to determine a shell's title trim. That is, the space occupied by the close, minimize, and maximize buttons and the system menu (if visible at all).
To get a hint though, it should be possible to use shell.computeTrim(0, 0, titleSize.x, titleSize.y). The returned rectangle's width field should give an approximation of the width needed for the shell.
Related
My application has a form for filling in the names and addresses of a donor. Each donor gets a closable tab and each tab has an address form.
The problem is that the application runs in a regular application window and therefore gets scaled to all different sizes. If I make the width and height of the text fields static, they all stay in the upper left of the window on a big screen. If I make them dynamic, the form looks bad because of massive boxes for relatively small amounts of text (i.e. first name). If I space them out dynamically, I end up with large gaps in between the boxes.
What is the best way to deal with this issue? Is there a UI construct normally used for this (so far the only one I've seen used has been to put the form in a non-scalable modal dialog, which I can't do because of the tab-based UI).
Thanks
Just a suggestion- an easy way out, taken by lots of web designers *(I know your app is not browser-based):
Constrain the content to a fixed size (e.g. 800px), and center that box horizontally. If the user maximizes their window, they see the 800px content centered with large empty gaps to right and left.
IMHO, this is not the best, but it doesn't look as bad as if it were packed into the upper left.
This is a graphic design question, not so much about the technology...
I created a program that deals with combo boxes, and I ran across a problem a Mac user showed me. Mac apparrently resizes JComboBox's and JButton's even if I set the width. The width of all the combo boxes on Windows are different since they are supposed to, but on OSX it's all the same width and size making it impossible to read half the entries of in the combo-box because it's all cut off when you try to select a selection. How can I fix or prevent this?
So my question is, how do you stop an operating system from auto-resizing the swing tools, or how do I make the selections in the JCombBox's readable and not cut off to like "Boxes" instead of "Bo...?"
As shown here, don't set the width; that is the purview of the UI delegate, com.apple.laf.AquaComboBoxUI. Instead, let the JComboBox calculate it's own preferred size based on the font metrics that inevitably vary from one platform to another.
If you still have problems, this example may form the basis for your sscce.
I have a Java application, and in order to find the size of the screen to use, I do the following, for example:
Toolkit.getDefaultToolkit().getScreenSize().width;
Toolkit.getDefaultToolkit().getScreenSize().height;
In my application, I am painting some items on the screen. And to determine the position, I use these values for width and height (because I want a particular item at the very bottom).
But, I'm finding that it is going off the screen, even though it's position doesn't exceed what the value for the height of my screen is.
Then, I realized I'm on a Mac, and the window that pops up for the Java application starts below the little toolbar menu thing at the top of my Mac (you know, the thing that has the time, the battery, etc). Do I need to take the height of that bar into consideration in my application? If so, is there an easy way to say "if I'm on a mac, then subtract something from the height." Also, what is that value of the height of that Menu Bar?
To get the maximum usable area, minus taskbars and menu bars, use the following:
Rectangle rect = GraphicsEnvironment.getLocalGraphicsEnvironment().getMaximumWindowBounds();
From the docs:
Returns the maximum bounds for centered Windows. These bounds account
for objects in the native windowing system such as task bars and menu
bars.
This may not be explained the best but here it goes.
I have a window of 2 by 2 square icons. I found a custom layout script that spaces these equally on the screen. These 4 icons consist of a square background with a little image and title.
At the moment the width and height are defined in dp. But that stretches or shrinks the text. I am assuming I need to use fixed values. I understand that there are 4 generalised screen resolutions.
My question is, for small I would have to set the width and heights to x and y, but when the screen gets bigger due to larger devices I would have to increase x and y to keep some sort of continuity.
Is there a minimum and maximum width and height of screens for each size? How do other people get around these issues.
Sorry if it is a bit broad and sweeping, but I am new to creating dynamic (ish) displays for multiple resolutions.
Any help and advice will be greatly appreciated.
Google has actually documented this well. When you load your images in your res folder, you will need to simply put high, medium, and low res versions of your file into the file with the same name (but with hdpi and so forth appended to the name of the file). Android will handle which file to choose based on the screen size. I could go through how to do this, but this link covers the details of what I'm talking about in greater detail. Also, check out this question I answered a while back. It has a lot to do with your question.
I'm making an application that has many lines of data coming back from a Database stub(which will become an Oracle database), and for some reason the scroll bar stops at about the 500th element. I'm wondering if there's anyway to have all the elements show within the scroll bar.
I'm assuming here that you're using Windows, because there is a fairly general problem with scrollbars on Windows: the maximum value is a short int, 32,768. Therefore, if the height of the inner composite of a ScrolledComposite is greater than 32,768 pixels, the composite will be clipped.
I haven't found a robust way of fixing this, but there is a workaround: separate the scrollbar from the composite that you wish to scroll. You can't create a ScrollBar, but you can make a ScrolledComposite that is precisely as wide as a ScrollBar, then attach a ScrollListener to it and have it adjust the layout position of the scrolling composite.
Somewhere I have a snippet, but I'm not even exactly sure if this diagnosis applies to your scenario.
You might need to set the minimum and maximum values of the ScrollBar. You would use the setMinimum() and setMaximum() methods, respectively.
It's also a good idea to set the page increment. This is the number of scroll lines that the selected value changes by when the user clicks the area between the thumb and the arrow buttons, or presses the Page Up or Page Down buttons. You would use the setPageIncrement() method.
Finally, Oracle may impose a maximum number of rows you can retrieve from a table. I believe the default is 500 rows.