[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
[platform-swt-dev] Execute swt program success inside Eclipse, but failure execute it as a standalone jar file
|
Dear friends,
After I upgrade my Eclipse to LUNA, I got a strange error. I could execute a SWT program success inside the Eclipse, but I could not do it as a standalone jar file.
The attachment file is a simple java example file (CTestSWT.java). It can be run success inside the Eclipse, and a window can be display as attachment file (window.png), and the text output as blow.
Point {75, 14} 200
Point {82, 16} 200
Point {86, 17} 200
Point {95, 20} 200
Point {104, 21} 200
Point {110, 23} 200
Point {129, 25} 200
Point {135, 26} 200
Point {139, 28} 200
Point {154, 30} 200
Point {160, 31} 200
Point {168, 33} 200
Point {179, 35} 200
Point {189, 36} 200
Point {195, 38} 200
Point {208, 40} 200
After I export a jar file from the Eclipse, I got a jar file (CTestSWT.jar). I try to execute it standalone. the command line I used is
"java -classpath testswt.jar:swt.jar:org.eclipse.core.commands.jar:org.eclipse.core.runtime.jar:org.eclipse.equinox.common.jar:org.eclipse.jface.jar: testswt/CTestSWT"
Although this java code execute success inside Eclipse, but it failure now. The window could be display, and I got an endless loop according to the text output. Besides it, two error messages were print out. The text output is showed as blew.
wgl@athena:~/home/SoftDev/dev/CurveSpirit/project/bin$ java -classpath testswt.jar:swt.jar:org.eclipse.core.commands.jar:org.eclipse.core.runtime.jar:org.eclipse.equinox.common.jar:org.eclipse.jface.jar: testswt/CTestSWT
(Test SWT:20502): Gtk-CRITICAL **: gtk_hsv_to_rgb: assertion 's >= 0.0 && s <= 1.0' failed
(Test SWT:20502): Gtk-CRITICAL **: gtk_hsv_to_rgb: assertion 's >= 0.0 && s <= 1.0' failed
Point {75, 14} 200
Point {75, 16} 200
Point {75, 17} 200
Point {75, 20} 200
Point {75, 21} 200
Point {75, 23} 200
Point {75, 25} 200
Point {75, 26} 200
Point {75, 28} 200
Point {75, 30} 200
Point {75, 31} 200
Point {75, 33} 200
Point {75, 35} 200
Point {75, 36} 200
Point {75, 38} 200
Point {75, 40} 200
Point {75, 41} 200
Point {75, 43} 200
Point {75, 46} 200
Point {75, 48} 200
Point {75, 49} 200
Point {75, 51} 200
Point {75, 53} 200
Point {75, 54} 200
Point {75, 56} 200
Point {75, 58} 200
Point {75, 59} 200
Point {75, 61} 200
Point {75, 63} 200
Point {75, 64} 200
Point {75, 67} 200
Point {75, 68} 200
Point {75, 69} 200
Point {75, 72} 200
Point {75, 73} 200
Point {75, 74} 200
Point {75, 78} 200
Point {75, 79} 200
Point {75, 80} 200
..........
..........
My operate system is Debian testing, the jdk is OpenJDK 7u65-2.5.2-4 which is install from Debian, and the Eclipse is LUNA. The phenomenon is very strange, and it was not occur in older version of Eclipse.
What is wrong? Would you please help me? Thank you very much!
With best regards
Gufstream
package testswt;
import org.eclipse.jface.window.*;
import org.eclipse.swt.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.widgets.*;
public class CTestSWT extends ApplicationWindow
{
public static void main(String[] args)
{
Display.setAppName("Test SWT");
CTestSWT frObj = new CTestSWT();
frObj.setBlockOnOpen(true);
frObj.open();
Display.getCurrent().dispose();
}
/**
* æ ¹æ®ç»å®å符串ãåä½åæå¤§å
许宽度确å®åå·ã
* @param device å建åä½ç设å¤ã
* @param comp ç¶æ§ä»¶ã
* @param text å符串ã
* @param font_data å使°æ®ã
* @param width å符串æ¾ç¤ºæå¤§å
许宽度ã
* @return åå·ã
*/
public static int findFontSizeWithWidth(Device device, Composite comp, String text, FontData font_data, int width)
{
Label lbl = new Label(comp, SWT.NONE);
lbl.setText(text);
int iFontSize = 8;
boolean blnFound = false;
while (!blnFound)
{
font_data.setHeight(iFontSize);
Font f = new Font(device, font_data);
lbl.setFont(f);
Point perfectSize = lbl.computeSize(SWT.DEFAULT, SWT.DEFAULT, false);
System.out.print(perfectSize);
System.out.print(" ");
System.out.println(width);
if (perfectSize.x <= width)
iFontSize++;
else
{
iFontSize--;
blnFound = true;
}
f.dispose();
}
return iFontSize;
}
public CTestSWT()
{
super(null);
}
@Override
protected Control createContents(Composite parent)
{
// çªå£æ é¢ã大å°
getShell().setText("Test SWT");
getShell().setSize(300, 300);
getShell().setLocation(200, 200);
// åç§°
Label lblName = new Label(parent, SWT.NONE);
lblName.setText("Test Words");
FontData font_data = new FontData("", 28, SWT.BOLD);
int iWidth = 200;
int iFontSize = findFontSizeWithWidth(getShell().getDisplay(), parent, "Curve Spirit", font_data, iWidth);
font_data.setHeight(iFontSize);
Font f = new Font(getShell().getDisplay(), font_data);
lblName.setFont(f);
f.dispose();
Point perfectSize = lblName.computeSize(SWT.DEFAULT, SWT.DEFAULT);
lblName.setBounds(190, 25, perfectSize.x, perfectSize.y);
return parent;
}
}
Attachment:
window.png
Description: PNG image