Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to get the Selection of JList items and show this in a JOptionPane as a message
    primarykey
    data
    text
    <p>I am creating a program where the user selects an item from a list, then the user enters a text to a TextField and then they press a button which then alerts the user of which item was selected alongside the text from the user.how do I go about alerting the user of which item was selected alongside the text from the user when the button is clicked.</p> <pre><code>import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; public class fruitList extends JFrame implements ListSelectionListener { private JTextField textField; private JList&lt;String&gt; fruitList; private JButton buttonwhich; private static fruitList frame; public static void main(String[] args) { fruitList frame = new fruitList(); frame.setTitle("Fruit List"); frame.setSize(350,150); frame.setVisible(true); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); } public fruitList() { final String[] FRUIT_NAME = {"Banana", "Apple", "Orange"}; setLayout(new FlowLayout()); buttonwhich = new JButton("Which"); fruitList = new JList&lt;String&gt;(FRUIT_NAME); fruitList.setVisibleRowCount(2); add(new JScrollPane(fruitList)); fruitList.addListSelectionListener(this); textField = new JTextField(10); add(textField); add(buttonwhich); ButtonHandler handler = new ButtonHandler(); buttonwhich.addActionListener(handler); } class ButtonHandler implements ActionListener { public void actionPerformed(ActionEvent e) { JOptionPane.showMessageDialog(frame, "You Pressed \t" + e.getActionCommand()); } } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload