JDialogのすべてのコンテンツを単純な画像に置き換える方法を見つけようとしています。これは、私が取り組んでいるプロジェクトのアバウトページ用であり、ユーザーが[アバウト]セクションをクリックすると、JDialogのスタイルでポップアップする(フォーカスが失われると消える)画像が必要です。例:http : //www.tecmint.com/wp-content/uploads/2012/08/About-Skype.jpg Skypeには、「About」ページとして作成した画像のみが表示されます。Java(swing)で「画像ダイアログ」を作成するにはどうすればよいですか?
17920 次
3 に答える
6
Java(swing)で「画像ダイアログ」を作成するにはどうすればよいですか?
ImageIcon を含む JLabel で装飾されていない JDialog を使用します。
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
JLabel label = new JLabel( new ImageIcon(...) );
dialog.add( label );
dialog.pack();
dialog.setVisible(true);
于 2013-03-07T04:43:27.503 に答える
4
BufferedImage image = ImageIO.read(new File("myfile.png"));
JLabel picLabel = new JLabel(new ImageIcon(image));
JOptionPane.showMessageDialog(null, picLabel, "About", JOptionPane.PLAIN_MESSAGE, null);
于 2013-03-06T21:42:10.203 に答える
3
さあ、コードに注釈を付けました
import javax.swing.JOptionPane; //imports
import javax.swing.JLabel;
import javax.swing.JFrame;
import javax.swing.ImageIcon;
import java.awt.Toolkit;
import java.awt.Dimension;
public class img{
public static void main(String[] args){
JFrame f = new JFrame(); //creates jframe f
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); //this is your screen size
f.setUndecorated(true); //removes the surrounding border
ImageIcon image = new ImageIcon(diceGame.class.getResource("image.png")); //imports the image
JLabel lbl = new JLabel(image); //puts the image into a jlabel
f.getContentPane().add(lbl); //puts label inside the jframe
f.setSize(image.getIconWidth(), image.getIconHeight()); //gets h and w of image and sets jframe to the size
int x = (screenSize.width - f.getSize().width)/2; //These two lines are the dimensions
int y = (screenSize.height - f.getSize().height)/2;//of the center of the screen
f.setLocation(x, y); //sets the location of the jframe
f.setVisible(true); //makes the jframe visible
}
}
[[OLD]]以下のコードは、あなたが探していることを実行します。
import javax.swing.JOptionPane;
import javax.swing.JLabel;
import javax.swing.ImageIcon;
public class img{
public static void main(String[] args){
JLabel lbl = new JLabel(new ImageIcon(diceGame.class.getResource("image.png")));
JOptionPane.showMessageDialog(null, lbl, "ImageDialog",
JOptionPane.PLAIN_MESSAGE, null);
}
}
于 2013-03-06T21:49:54.637 に答える