我试图找到一种方法来将JDialog的所有内容替换为简单的图像。 这是为我正在处理的项目的关于页面而设计的,当用户单击关于部分时,我想要一个图像以JDialog的样式弹出(并在焦点丢失时消失)。 例如:http://www.tecmint.com/wp-content/uploads/2012/08/About-Skype.jpg Skype只显示他们创建的图像作为其“关于”页面。 如何在Java(swing)中创建“图像对话框”?Java,我怎样才能弹出一个对话框只有一个图像?
4
A
回答
2
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
}
}
[[老] 下面的代码会做你要找的内容。
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);
}
}
5
我怎样才能让在Java中(摇摆) “图像对话”?
使用未修饰的JDialog包含一个ImageIcon一个JLabel:
JDialog dialog = new JDialog();
dialog.setUndecorated(true);
JLabel label = new JLabel(new ImageIcon(...));
dialog.add(label);
dialog.pack();
dialog.setVisible(true);
相关问题
- 1. 使用ASP.NET,我怎样才能通过同一个对话框
- 2. 我怎样才能变出一个班?
- 3. 我怎样才能从一个deque中弹出()很多元素?
- 4. 我怎样才能有一个弹出窗口来自一个选项卡而不是一个视图
- 5. 我怎样才能让这只有一个元素?
- 6. 我怎样才能使一个背景图像scalebale
- 7. 我怎样才能在一个div中垂直堆叠图像
- 8. 我怎样才能让一个精灵与intercambiable图像
- 9. 我怎样才能拖动一个图像按钮android
- 10. 我怎样才能在一个div响应的图像?
- 11. Applescript,我试图使一个对话框中出现一个对话框,我只有总数量的3我有
- 12. 我怎样才能<br>两个图像旁边的一个图像?
- 13. 我怎样才能在另一个UI线程上显示对话框
- 14. 我怎样才能在一个XML Schema
- 15. 我怎样才能成为一个index.jade?
- 16. 我怎样才能找到一个DataTable
- 17. 我怎样才能生成一个PDF
- 18. 我怎样才能在一个div
- 19. 我怎样才能得到一个TD
- 20. 我怎样才能在一个列表
- 21. 我怎样才能纹理一个GL_TRIANGLE_STRIP?
- 22. 我怎样才能在一个空间{{}}
- 23. 只有多于一个,我怎样才能得到最后一个?
- 24. 我怎样才能得到一个JSON像这样用JavaScript
- 25. 我怎样才能让一个java程序一直运行?
- 26. 我怎样才能显示一个jQuery UI对话框,而不是一个警告框,大量文本的
- 27. db4o:我们怎样才能得到只有一个对象的数据?
- 28. 我怎样才能使一个div扩大点击一次只打开一个?
- 29. 我怎样才能得到一个图表只有使用highcharts的传说
- 30. 我怎样才能分配一个JavaScript变量的会话值
看起来不错,但我能做些什么来去除的JOptionPane的窗口边框,使图像是唯一剩下的东西? – vejmartin 2013-03-06 22:00:32
我已经为你编辑了答案。 – MeryXmas 2013-03-06 22:31:23
'ImageIcon image = new ImageIcon(diceGame.class.getResource(“image.png”));''从哪里来,我的意思是明确的diceGame。为什么它不是简单的“img.class〜”,因为该类被称为? – N30 2014-05-07 11:09:13