implemented scrollbar with search results with error message if none are found

gui
David Groys 2024-06-15 16:34:36 +02:00
parent 5eaff1161b
commit 1a45bc23ec
1 changed files with 68 additions and 26 deletions

View File

@ -59,7 +59,7 @@ public class Main extends JFrame {
private JButton changePasswordButton; private JButton changePasswordButton;
private JButton changeDetailsButton; private JButton changeDetailsButton;
private JButton logOutButton; private JButton logOutButton;
private JScrollPane jsp = new JScrollPane(); private JScrollPane jsp;
private JPanel destinationButtons = new JPanel(); private JPanel destinationButtons = new JPanel();
private JPanel changePassword; private JPanel changePassword;
@ -154,7 +154,6 @@ public class Main extends JFrame {
logOutButtonCreate(); logOutButtonCreate();
changeDetailsButtonCreate(); changeDetailsButtonCreate();
changePasswordButtonCreate(); changePasswordButtonCreate();
jsp.add(destinationButtons);
menuLabel.setBounds(180, -125, 300, 300); menuLabel.setBounds(180, -125, 300, 300);
searchPLZ_ORT.setBounds(20, 50, 300, 100); searchPLZ_ORT.setBounds(20, 50, 300, 100);
searchConfirmButton.setBounds(346, 70, 110, 30); searchConfirmButton.setBounds(346, 70, 110, 30);
@ -163,7 +162,6 @@ public class Main extends JFrame {
logOutButton.setBounds(340, 430, 130, 30); logOutButton.setBounds(340, 430, 130, 30);
changeDetailsButton.setBounds(340, 398, 130, 30); changeDetailsButton.setBounds(340, 398, 130, 30);
changePasswordButton.setBounds(340, 366, 130, 30); changePasswordButton.setBounds(340, 366, 130, 30);
jsp.setBounds(50,50,300,400);
menu.add(menuLabel); menu.add(menuLabel);
menu.add(searchPLZ_ORT); menu.add(searchPLZ_ORT);
@ -522,35 +520,73 @@ public class Main extends JFrame {
@Override @Override
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
ArrayList<String> orte = facade.search(getTextfieldContent(searchPLZ_ORT, "ortSuche")); ArrayList<String> orte = facade.search(getTextfieldContent(searchPLZ_ORT, "ortSuche"));
JPanel destinationButtonsProxy = new JPanel(new FlowLayout()); JPanel destinationButtonsProxy = new JPanel();
for(String s : orte){ destinationButtonsProxy.setLayout(new BoxLayout(destinationButtonsProxy, BoxLayout.Y_AXIS));
String[] ortUndPLZ = s.split(";"); if (orte.size() > 0) {
String address = ortUndPLZ[1] + ", " + ortUndPLZ[0]; for (String s : orte) {
JButton jb = new JButton(address); String[] ortUndPLZ = s.split(";");
jb.setSize(100,20); String plz = ortUndPLZ[0];
jb.addActionListener(new ActionListener() { String address = ortUndPLZ[1] + "," + plz + " " + facade.distance(plz);
@Override JButton jb = new JButton(address);
public void actionPerformed(ActionEvent e) { jb.setPreferredSize(new Dimension(290, 40));
JFrame jf = new JFrame(); jb.addActionListener(new ActionListener() {
JPanel jp = new JPanel(new FlowLayout()); @Override
String[] details = facade.destination_details(ortUndPLZ[0]); public void actionPerformed(ActionEvent e) {
for(String ss : details) { JFrame jf = new JFrame();
JLabel jl = new JLabel(ss); JPanel jp = new JPanel(new FlowLayout());
jp.add(jl); String[] details = facade.destination_details(plz);
for (String ss : details) {
JLabel jl = new JLabel(ss);
jp.add(jl);
}
jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
jf.add(jp);
jf.setSize(100, 400);
jf.setVisible(true);
} }
jf.setDefaultCloseOperation(DISPOSE_ON_CLOSE); });
jf.add(jp); destinationButtonsProxy.add(jb);
jf.setSize(100,400); }
} destinationButtons = destinationButtonsProxy;
}); destinationButtons.revalidate();
//erzeuge aus adresse einen Button destinationButtons.repaint();
try {
menu.remove(jsp);
} catch (Exception jspNotYetIncluded) {
}
jsp = new JScrollPane(destinationButtons);
jsp.setBounds(40, 110, 244, 336);
jsp.revalidate();
jsp.repaint();
menu.add(jsp);
menu.revalidate();
menu.repaint();
}
else {
destinationButtonsProxy = new JPanel();
JLabel jl = new JLabel("Kein Ergebnis");
jl.setFont(new Font("Arial", Font.PLAIN, 38));
destinationButtonsProxy.add(jl);
destinationButtons = destinationButtonsProxy;
destinationButtons.revalidate();
destinationButtons.repaint();
try {
menu.remove(jsp);
} catch (Exception jspNotYetIncluded) {
}
jsp = new JScrollPane(destinationButtons);
jsp.setBounds(40, 110, 244, 336);
jsp.revalidate();
jsp.repaint();
menu.add(jsp);
menu.revalidate();
menu.repaint();
} }
destinationButtons = destinationButtonsProxy;
menu.revalidate();
} }
}); });
} }
private void randDestinationsCarButtonCreate() { //Auto Icon hinzufügen private void randDestinationsCarButtonCreate() { //Auto Icon hinzufügen
randDestinationsCarButton = new JButton(); randDestinationsCarButton = new JButton();
randDestinationsCarButton.setPreferredSize(new Dimension(150, 80)); randDestinationsCarButton.setPreferredSize(new Dimension(150, 80));
@ -807,6 +843,12 @@ public class Main extends JFrame {
}); });
} }
public void jspCreate(){
jsp = new JScrollPane();
jsp.setSize(100,100);
}
private String getTextfieldContent(JPanel panel, String name) { private String getTextfieldContent(JPanel panel, String name) {
for (Component component : panel.getComponents()) { for (Component component : panel.getComponents()) {
if (component instanceof JTextField && name.equals(component.getName())) { if (component instanceof JTextField && name.equals(component.getName())) {