Java SWT - placing image buttons on the image background
Posted
by
foma
on Stack Overflow
See other posts from Stack Overflow
or by foma
Published on 2011-08-31T10:49:28Z
Indexed on
2012/08/29
15:38 UTC
Read the original article
Hit count: 224
swt
I am trying to put buttons with images(gif) on the background which has already been set as an image (shell.setBackgroundImage(image)) and I can't figure out how to remove transparent border around buttons with images. I would be grateful if somebody could give me some tip about this issue.
Here is my code:
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
public class Main_page {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, "bg.gif");
shell.setBackgroundImage(image);
shell.setBackgroundMode(SWT.INHERIT_DEFAULT);
shell.setFullScreen(true);
Button button = new Button(shell, SWT.PUSH);
button.setImage(new Image(display, "button.gif"));
RowLayout Layout = new RowLayout();
shell.setLayout(Layout);
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
}
Sorceror, thanks for your answer I will definitely look into this article. Maybe I will find my way. So far I have improved my code a little bit. Firstly, I managed to get rid of the gray background noise. Secondly, I finally succeeded in creating the button as I had seen it in the first place. Yet, another obstacle has arisen. When I removed image(button) transparent border it turned out that the button change its mode(from push button to check box). The problem is that I came so close to the thing I was looking for and now I am a little puzzled. If you have some time please give a glance at my code.
Here is the code, if you launch it you will see what the problem is(hope you didn't have problems downloading images):
import org.eclipse.swt.widgets.*;
import org.eclipse.swt.layout.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
public class Main_page {
public static void main(String[] args) {
Display display = new Display();
Shell shell = new Shell(display);
Image image = new Image(display, "bg.gif"); // Launch on a screen 1280x1024
shell.setBackgroundImage(image);
shell.setBackgroundMode(SWT.TRANSPARENT);
shell.setFullScreen(true);
GridLayout gridLayout = new GridLayout();
gridLayout.marginTop = 200;
gridLayout.marginLeft = 20;
shell.setLayout(gridLayout);
// If you replace SWT.PUSH with SWT.COLOR_TITLE_INACTIVE_BACKGROUND
// you will see what I am looking for, despite nasty check box
Button button = new Button(shell, SWT.PUSH);
button.setImage(new Image(display, "moneyfast.gif"));
shell.open();
while (!shell.isDisposed()) {
if (!display.readAndDispatch())
display.sleep();
}
display.dispose();
}
© Stack Overflow or respective owner