gpt4 book ai didi

java - 在选项卡 Pane 中显示多个图像

转载 作者:行者123 更新时间:2023-11-30 04:52:26 27 4
gpt4 key购买 nike

有人可以建议我在 jtabbedpane 选项卡中显示多个图像的方法吗?例如,我想显示图像的缩略图 View ,并选择应在其他选项卡中打开的图像?

我已经放置了部分代码来展示我想要的内容。在这里,我绘制了图像,但实际上我想加载这些图像以允许他们选择进行编辑。

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;
}
}
}

最佳答案

  1. JPanelGridLayoutGridBagLayout 一起使用来显示 JLabel 列表。
  2. 为每个标签设置一张图像,并将一个 MouseListener 附加到每个标签。单击标签后,创建一个带有大图像的新 JPanelJLabel 并将其添加到选项卡

关于java - 在选项卡 Pane 中显示多个图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9537921/

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