JavaチュートリアルHow to Create Translucent and Shaped Windowsはなぜ機能しませんでしたか? Java 6またはJava 7の最新バージョンを使用していますか? May/June issue of Java Magazineには、Java 7を必要とするシェイプされた透明なウィンドウに関するチュートリアルがありました。Javaの雑誌を読むためには、おそらくサインアップする必要があります。
import java.awt.*; //Graphics2D, LinearGradientPaint, Point, Window, Window.Type;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
/**
* From JavaMagazine May/June 2012
* @author josh
*/
public class ShapedAboutWindowDemo {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
//switch to the right thread
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
JFrame frame = new JFrame("About box");
//turn of window decorations
frame.setUndecorated(true);
//turn off the background
frame.setBackground(new Color(0,0,0,0));
frame.setContentPane(new AboutComponent());
frame.pack();
//size the window
frame.setSize(500, 200);
frame.setVisible(true);
//center on screen
frame.setLocationRelativeTo(null);
}
}
);
}
private static class AboutComponent extends JComponent {
public void paintComponent(Graphics graphics) {
Graphics2D g = (Graphics2D) graphics;
//create a translucent gradient
Color[] colors = new Color[]{
new Color(0,0,0,0)
,new Color(0.3f,0.3f,0.3f,1f)
,new Color(0.3f,0.3f,0.3f,1f)
,new Color(0,0,0,0)};
float[] stops = new float[]{0,0.2f,0.8f,1f};
LinearGradientPaint paint = new LinearGradientPaint(
new Point(0,0), new Point(500,0),
stops,colors);
//fill a rect then paint with text
g.setPaint(paint);
g.fillRect(0, 0, 500, 200);
g.setPaint(Color.WHITE);
g.drawString("My Killer App", 200, 100);
}
}
}
この問題の解決方法はありますか?私は同じ問題に直面しています。私はScreencast-O-Maticのようなアプリケーションを作っています。これはWindows OSでうまく動作しますが、Linuxでは動作しません。何か見つかったらここに提案してください。http://stackoverflow.com/questions/25009276/swing-works-different-on-different-platform – tarkikshah
いいえ、私はJavaで他の問題があったので、スクリーンキャストアプリケーションのPyQtに戻ってきました。 –
ok ...ありがとう.. – tarkikshah