right selection of item in list
This commit is contained in:
parent
0cb25ef1ce
commit
e8ee2b6efa
@ -1,9 +1,10 @@
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.*;
|
||||
import java.io.*;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.File;
|
||||
import java.io.FileReader;
|
||||
import java.io.IOException;
|
||||
import java.util.Vector;
|
||||
|
||||
public class OrderFrame extends JFrame {
|
||||
@ -15,10 +16,8 @@ public class OrderFrame extends JFrame {
|
||||
private Vector<Product> bla = new Vector();
|
||||
private JList list;
|
||||
|
||||
// TODO: Add property for products
|
||||
|
||||
public OrderFrame() {
|
||||
this.setTitle("Lukas HEiligenbrunner");
|
||||
this.setTitle("Lukas Heiligenbrunner");
|
||||
this.add(buttonOpen, BorderLayout.NORTH);
|
||||
this.add(productPanel);
|
||||
|
||||
@ -52,14 +51,9 @@ public class OrderFrame extends JFrame {
|
||||
|
||||
|
||||
list = new JList(bla);
|
||||
list.addListSelectionListener(new ListSelectionListener() {
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
|
||||
productPanel.setData(bla.get(e.getLastIndex()));
|
||||
System.out.println("something was selected" + e.getLastIndex());
|
||||
|
||||
}
|
||||
list.addListSelectionListener(e -> {
|
||||
productPanel.setData(bla.get(list.getSelectedIndex()));
|
||||
System.out.println("something was selected" + e.getLastIndex());
|
||||
});
|
||||
this.add(list, BorderLayout.WEST);
|
||||
|
||||
@ -69,7 +63,7 @@ public class OrderFrame extends JFrame {
|
||||
this.setVisible(true);
|
||||
}
|
||||
|
||||
public void openFileAndFillToListBox(String filename) {
|
||||
private void openFileAndFillToListBox(String filename) {
|
||||
bla.clear();
|
||||
File myfile = new File(filename);
|
||||
try {
|
||||
@ -97,8 +91,6 @@ public class OrderFrame extends JFrame {
|
||||
}
|
||||
|
||||
reader.close();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user