当选择 JComboBox 项时如何将图像实现到 JFrame 中?

问题描述 投票:0回答:1
JComboBox nombresLista = new JComboBox(nombres);
nombresLista.setBounds(250, 110, 150, 30);

JComboBox nombresLista2 = new JComboBox(nombres);
nombresLista2.setBounds(700, 110, 150, 30);

JLabel lista = new JLabel();
lista.setText("Lista de nombres");
lista.setBounds(950, 70, 100,50);

nombresLista.addActionListener(new ActionListener() {
    @Override
    public void actionPerformed(ActionEvent e) 
    {

    }
});

我想在我的

JFrame
中实现一个图像,其中包含该人角色的简短描述,并显示他/她的图像。我能做些什么?我对此真的很陌生。帮助。

我看过视频,但无法真正得到我的问题的答案。我不知道如何通过每次选择

JComboBox
显示图像。预先感谢您阅读本文。

java swing
1个回答
0
投票

您可以将图像作为图标放入按钮中。

jbutton.setIcon(new ImageIcon(ImageData.loadImage()));

当然你必须加载图像。

ImageIO.read(new FileInputStream(path.toString()));
© www.soinside.com 2019 - 2024. All rights reserved.