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