I was wondering if it would be possible to create a window using SWT that has either a transparent background or no background (i.e., just buttons and texts are shown floating).
I've tried using the setBackground() function like:
shell.setBackground(display.getSystemColor(SWT.TRANSPARENT));
but it will just show a window with a black background rather than a transparent one. any way to do this?
See How to Create Translucent and Shaped Windows (Java 7+).
..(SWT) uses the native window scheme, rather than an ugly/custom one. ..
Use Swing with the native PLAF.
Update 1
Me.
..you want component (button etc.), not Window (or ancestor) transparency?
To which you replied.
not necessarily the component itself, but the 'area' in which the component resides in. if you look at the Nested Layout Example above, you see the win 7's transparent border, then you see the normal gray background. I'd like that gray background to also be transparent.
You can create a window with per-pixel translucency, where each pixel has its own alpha value. With this feature you can, for example, create a window that fades away to nothing by defining a gradient in the alpha values.
And as an aside, that 3rd screenshot is actually the 2nd image ripped directly from the page that is linked in the 1st sentence of my reply (the same page where I got the above quote). Did you follow the link, read the page (look at the screenshots), try the working examples?
Related
In the screenshot below, you can see four buttons in the selected area. I want to mimic this kind of buttons in my GUI application. Each of these buttons has an image on them (play,stop, forward, rewind). I can use the icon property of the button to add an image to it.
When the user hovers the mouse pointer over a button, three things happen:
it changes color- I don't need this feature.
It displays a tool tip. I know how to do it by using the tooltip
text property of a button.
Most importantly, these buttons don't have a border around them,
That is their bounds are not visible at all. It's just the image
which is visible. I want to do something like this. But when I add
an image to a button, its border does not go away (I mean it's
bounds are clearly visible in the form of a line - as you can see in
the second image)
So what property of an button should I manipulate, or what method should I use, to make its borders (and every visible trace of the button except the image present on it) invisible?
A border is painted when setBorderPainted is set to true, otherwise not:
setBorderPainted:
Sets the borderPainted property. If true and the button has a border,
the border is painted. The default value for the borderPainted
property is true. Some look and feels might not support the
borderPainted property, in which case they ignore this.
Note that some look and feels may ignore this property.
Update:
The default look and feel is called CrossPlatformLookAndFeel. This is not a look and feel but an indicator of the default one. What you get as default depends on the platform you are using. See How to Set the Look and Feel for details. I personally loke the Nimbus Look and Feel, but I have encountered some problems with it. I am not sure if it respects setBorderPainted, but I will not be surprised if it does not.
I have a need to make my dialog partially transparent. Pull out a tab from google chrome to create a new window, while dragging the shape it makes is the shape that I want to make, minus see-through.
The point is that my dialog is a fairly simple and standard dialog, but I need one chunk of it cut out and transparent. Double points if that area is not part of the dialog so clicking there will lose focus from the dialog.
you can set the opacity.
http://java.sun.com/developer/technicalArticles/GUI/translucent_shaped_windows/#Setting-the-Opacity-Level-of-a-Window
I see what you mean by chrome page tab. In this case you may have to have an underlying panel which is transparent, this panel would then contain the tab in the top corner, and the rest of the page underneath. ie 2 separate components
hope that is what you very looking for
I'm trying to provide a progress report for a slow operation, in the form of text scrolling up from the bottom of the screen with details on what's going on - it's an effect you may have seen a few times in video games when they're loading maps, making network connections and suchlike.
Glass pane seems to be the way to get the text overlay, that much I have working. My problem is exactly what component to use for the actual text display.
JTextArea can display text, but as far as I can see, it can only do it from the top of the screen down - is there a way to make it scroll text up from the bottom of the screen?
JLabel by contrast can align the first line of text to the bottom of the screen, and even take appended text on that line, but when I add more lines separated by newline characters, it just seems to swallow them up even after calling repaint and validate. Is there a way to make it scroll up with the new text?
Or is there another component I should be using instead?
I really like JXLayer for effects layered over Swing components. JXLayer was at one point scheduled to be included in Java 7. Unfortunately the moving around that has been going on Java.net lost all the good content that the author had. There are still some other great resources around (Java 7 required for this one) on the web. I use JXLayer to provide panels with a busy state having a web-like spinner and greyed out appearance.
Another alternative (not as capable as JXLayer IMHO) is MigLayout has absolute positioning, which is maybe easier than the GlassPane.
JLabel would be the easiest. Otherwise you will have to override paintComponent to do anything fancy like animating the text movement.
I've created an app with a small window (the size of a combo box). I need to create a floating panel that sits outside the window, next to the selected item in a JComboBox. (See attached image).
I've been reading about the JComboBox.setRenderer(customRenderer) etc. But was just wondering before I go down this path, whether it is at all possible to render something outside the window. I suspect it is, as the combobox itself manages to render it's popup list outside the window.
I'm very new to Swing, so any advice would be appreciated.
It's not possible with the custom renderer since Swing components are light weight. That is, Java is given a native window and all the component drawing takes place in that window. In your case, that is the JFrame containing the combo box.
What you can do though is create a new undecorated window and set it's location accordingly and draw whatever you want inside it.
EDIT: When Java needs to paint outside it's window bounds (like the case of pop up messages or combo boxes drop downs) if the component falls inside the bounds it uses the swing light weight mechanism. But if the component falls out side the bounds it is automatically substituted with a awt heavy weight component that has it's own native drawing surface outside the active window.
I've implemented similar idea using combobox renderers and tooltips on them. Content of every item's tooltip can be customized and rendered using HTML. Location of the tooltip can be set outside of the item itself thus creating design very similar to the one presented in your question.
Here is the starting point for you:
http://www.java2s.com/Code/Java/Swing-Components/ToolTipComboBoxExample.htm
I'm having a hard time trying to make a Java program with just a shape (e.g rectangle) as main window. I don't want the shape to be inside the 'OS-window' (with buttons to close and minimize etc..)
I don't know if you can draw directly on the screen in Java (I tend to think you can't). But you could create a JDialog (which doesn't appear in the taskbar) and call setUndecorated(true) on it (to get rid of the title bar). Then you can do whatever custom painting you want with it.
Edit: kts points out that JWindow will work even better for this purpose. From the Javadocs:
It does not have the title bar, window-management buttons, or other trimmings associated with a JFrame, but it is still a "first-class citizen" of the user's desktop, and can exist anywhere on it.
And there's even a no-argument constructor, so you don't have to worry about passing in a null owner!
For more exotic shapes: translucent and shaped windows. Works only in 6u10 and later.