gpt4 book ai didi

java - JFrame 中的图像缩略图 View /编辑器

转载 作者:行者123 更新时间:2023-11-29 03:49:16 25 4
gpt4 key购买 nike

谁能建议我如何在一个选项卡中加载多个图像,然后在单击特定图像后它应该在另一个选项卡中打开以进行图像处理?

这是我的代码的一部分。相反,如果绘制图像我实际上需要打开加载图像并且在选择特定图像时它应该打开到其他选项卡。请建议我如何使用 jlist 或任何其他方式完成..

import javax.swing.*;
import java.awt.*;
import java.awt.Event.*;
import java.io.File;
import java.awt.image.BufferedImage;
import javax.imageio.ImageIO;
import java.io.IOException;

public class SwindDesign {
public static void main(String[] args) throws IOException {
JFrame frame = new JFrame("Split Pain");
frame.setSize(700, 500);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLayout(new GridLayout());

//panel
JPanel panel = new JPanel();
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
panel.add(new PicturePanel());

JTabbedPane jtp = new JTabbedPane();

jtp.addTab("Set Image", panel);
jtp.addTab("Compare Image", new JButton());
frame.add(jtp);

}
}
class PicturePanel extends JPanel {

File folder = new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures");
File[] listOfFiles = folder.listFiles();
ImageIcon[] img ;
JComponent lblimg;
JTabbedPane jtp = new JTabbedPane();
private BufferedImage[] b = new BufferedImage[10];

public PicturePanel() throws IOException {
for (int i = 0; i < listOfFiles.length; i++) {
System.out.println("chek panth"+listOfFiles[i].getName().toString());
b[i] = ImageIO.read(new File("C:/Documents and Settings/All Users/Documents/My Pictures/Sample Pictures/" + listOfFiles[i].getName().toString()));
}
}

@Override
protected void paintComponent(Graphics g) {
super.paintComponents(g);
Graphics2D g2 = (Graphics2D) g;
int k = 10;
for (int j = 0; j < listOfFiles.length - 1; j++) {
g2.drawImage(b[j], k, 0, 100, 100, null);
k = k + 75;
}
}
}

最佳答案

could anyone suggest me how to load multiple..

使用循环。

..images..

使用ImageIO.read(File/URL/InputStream)

in on tab..

JPanel 添加到具有合适布局的选项卡,E.G. FlowLayoutGridLayout。将图像放入未修饰的 JButton 并将其添加到面板。

..and after clicking on a particular image..

为按钮添加一个ActionListener

..it should open inn a other tab for image processing.

JTabbedPane.addTab("图片名称", imageEditorComponent)

关于java - JFrame 中的图像缩略图 View /编辑器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9512878/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com