「java图片刷新」java图形界面刷新
本篇文章给大家谈谈java图片刷新,以及java图形界面刷新对应的知识点,希望对各位有所帮助,不要忘了收藏本站喔。
本文目录一览:
- 1、java repaint图片不刷新
- 2、急,关于JAVA图片刷新的问题
- 3、请问java的JLabel上的图片如何刷新?
- 4、java web项目上传一些图片,必须刷新文件夹才能显示图片,如何编写自动刷新代码??
- 5、java 更新image后如何刷新
java repaint图片不刷新
JFRAME上如果重写paint方法来绘制背景图片,是不会刷新的,只有在窗体放大,缩小,
最小化,最大化时才会刷新。
解决办法。
定制一个JPanel,重写paint方法。
将这个Jpanel放到窗体上,调用,JPANEL的repaint方法,就可以刷新了。
急,关于JAVA图片刷新的问题
是不是你原来的图片没有删除?把原来的图片移走试试
labeImage.setBounds(240, 40, 9999, 9999);
labeImage.setIcon(new ImageIcon("D:\\pic\\gf"));
labeImage.setBounds(240, 40,1024,768);
contentPane.add(labeImage);
请问java的JLabel上的图片如何刷新?
java jlabel 图片的更新及清空
Java jlabel 里显示衣服图片根据jcombobox的内容实现不了更新,
还有我想把jlabel的图片清空怎么实现!
jLabel.setIcon(null),编译出错。
麻烦大家指点一下
------解决方案--------------------
我运行label.setIcon(null)没有问题,给你一个例子,运行的时候,需要在工程目录下有images目录,该目录下加上1.jpg 2.jpg …… 8.jpg这样八个图片
Java codeimport java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.UIManager;
public class ImageRandomAccess2 implements ActionListener {
final static int NUM_IMAGES = 8;//显示的图片总数
final static int START_INDEX = 3;//初始化的时候默认显示的图片
ImageIcon[] images = new ImageIcon[NUM_IMAGES];//初始化数组
JPanel mainPanel, selectPanel, displayPanel;//三个面板
JLabel selectLabel=null;
JComboBox combobox=null;//控制显示有哪些图片,非随即滚动
JButton controlBtn=null;
JLabel imageIconLabel = null;
// Constructor
public ImageRandomAccess2() {
// Create the phase selection and display panels.
selectPanel = new JPanel();
displayPanel = new JPanel();
// Add various widgets to the sub panels.
addWidgets();
// Create the main panel to contain the two sub panels.
mainPanel = new JPanel();
mainPanel.setLayout(new GridLayout(2, 1, 5, 5));
mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
// Add the select and display panels to the main panel.
mainPanel.add(selectPanel);
mainPanel.add(displayPanel);
}
// Create and the widgets to select and display the images of peoples.
private void addWidgets() {
// Get the images and put them into an array of ImageIcon.
for (int i = 0; i NUM_IMAGES; i++) {
String imageName = "images/" + (i + 1) + ".jpg";
System.out.println("getting image: " + imageName);
// URL iconURL = ClassLoader.getSystemResource(imageName);
ImageIcon icon = new ImageIcon(imageName);
images[i] = icon;
}
// Create label for displaying images and put a border around
// it.
imageIconLabel = new JLabel();
imageIconLabel.setHorizontalAlignment(JLabel.CENTER);
imageIconLabel.setVerticalAlignment(JLabel.CENTER);
imageIconLabel.setVerticalTextPosition(JLabel.CENTER);
imageIconLabel.setHorizontalTextPosition(JLabel.CENTER);
imageIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createLoweredBevelBorder(),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
imageIconLabel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createEmptyBorder(0, 0, 10, 0),
imageIconLabel.getBorder()));
controlBtn=new JButton("无图片");
selectLabel=new JLabel("选择图片");
combobox=new JComboBox();
for(int i=0;iNUM_IMAGES;i++){
combobox.addItem(i);
}
selectLabel.setLabelFor(combobox);
// Display the first image.
imageIconLabel.setIcon(images[START_INDEX]);
imageIconLabel.setText("");
// Add border around the select panel.
selectPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Select Phase"),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
// Add border around the display panel.
displayPanel.setBorder(BorderFactory.createCompoundBorder(
BorderFactory.createTitledBorder("Display Phase"),
BorderFactory.createEmptyBorder(5, 5, 5, 5)));
// Add control button to select panel and image label to
// displayPanel.
selectPanel.add(selectLabel);
selectPanel.add(combobox);
selectPanel.add(controlBtn);
displayPanel.add(imageIconLabel);
// Listen to events from control button.
// controlBtn.addActionListener(this);
combobox.addActionListener(this);
controlBtn.addActionListener(this);
}
boolean run = false;
// Implementation of ActionListener interface.
public void actionPerformed(ActionEvent event) {
if(event.getSource()==combobox){
int imageIndex=combobox.getSelectedIndex();
imageIconLabel.setIcon(images[imageIndex]);
}
if(event.getSource()==controlBtn){
System.out.println("------------");
imageIconLabel.setIcon(null);
// imageIconLabel.setIcon(new ImageIcon());
}
}
// main method
public static void main(String[] args) {
// create a new instance of ImageRandomAccess
ImageRandomAccess2 phases = new ImageRandomAccess2();
// Create a frame and container for the panels.
JFrame mainFrame = new JFrame("ImangeRandomAccess");
// Set the look and feel.
try {
UIManager.setLookAndFeel(UIManager
.getCrossPlatformLookAndFeelClassName());
} catch (Exception e) {
}
mainFrame.setContentPane(phases.mainPanel);
// Exit when the window is closed.
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Show the converter.
mainFrame.pack();
mainFrame.setLocationRelativeTo(null);
mainFrame.setVisible(true);
}
}
java web项目上传一些图片,必须刷新文件夹才能显示图片,如何编写自动刷新代码??
图片不会自动显示是不是浏览器缓存问题~?就是譬如两次请求都是同一个地址,但是如果你存储的图片已经更改,但是名字没变,这样浏览器貌似是不会重新发出请求。你可以在请求时候附加一个随机数,
或者你可以再详细描述下,你说的文件夹是在哪里的文件夹,网络上的?~还是本地?你说显示图片是在哪里显示?页面上?还是本地文件夹里面?
java 更新image后如何刷新
一般都是 repaint(); 就行了。
执行这个,就会激活paintComponent()方法。
至于你说的图片完全不见了,你应该找找其它的原因,比如 img 这个对象是不是有问题。
java图片刷新的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java图形界面刷新、java图片刷新的信息别忘了在本站进行查找喔。