Mickeys
asked on
My dropdownlist and List is wrong
How do I get a dropdownlist (the one where it says america) to be smaller?
How do I get the the List (the one with the books in it) to be bigger?
In other word.....it should look nice. :-)
See code below.
How do I get the the List (the one with the books in it) to be bigger?
In other word.....it should look nice. :-)
See code below.
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
public class StoreGUI extends JFrame {
private static final long serialVersionUID = 1L;
private JFrame thisFrame;
private Container c;
private JPanel midPanel=new JPanel();
private JPanel userPanel=new JPanel();
private JLabel whoJL=new JLabel("Name");
private JTextField whoJTF=new JTextField(8);
private JLabel noJL=new JLabel("Number");
private JTextField noJTF=new JTextField(8);
private JPanel controlPanel=new JPanel();
JTextField txt;
private JButton loginJB=new JButton("Logga in");
private JButton logoutJB=new JButton("Logga ut");
private JButton regJB=new JButton("Registrera ny Användare");
private JButton addJB=new JButton("Lägg till vara");
private JButton updateJB=new JButton("Uppdatera vara");
private JButton removeJB=new JButton("Ta bort vara");
private JButton exitJB=new JButton("Exit");
String category[] = {"India","Germany","America","Russia"};
private JComboBox combo = new JComboBox(category);
private String books[] = {
("Ant: The Definitive Guide"+"covers/ant.gif"),
("Database Programming with JDBC and Java"+
"covers/jdbc.gif"),
("Developing Java Beans"+ "covers/beans.gif"),
};
private JList booklist = new JList(books);
class AppActionListener implements ActionListener{
public void actionPerformed(ActionEvent ae){
String name=whoJTF.getText();
String number=noJTF.getText();
JButton temp=(JButton)ae.getSource();
if(temp==logoutJB){
System.out.println("Looking up "+name);
noJTF.setText(number);
noJTF.setText("Not found!");
}
if(temp==addJB){
}
if(temp==updateJB){
}
if(temp==removeJB){
}
if(temp==loginJB){
whoJTF.setText("");
noJTF.setText("");
}
if(temp==exitJB){
System.exit(0);
}
}
}
public void showGUI() {
this.setLayout(new BorderLayout());
midPanel.setLayout(new FlowLayout());
userPanel.setLayout(new GridLayout(2,2));
userPanel.add(combo);
booklist.setVisibleRowCount(4);
JScrollPane pane = new JScrollPane(booklist);
userPanel.add(pane);
midPanel.add(userPanel);
this.add(midPanel, BorderLayout.CENTER);
controlPanel.setLayout(new FlowLayout());
loginJB.addActionListener(new AppActionListener());
controlPanel.add(loginJB);
logoutJB.addActionListener(new AppActionListener());
controlPanel.add(logoutJB);
regJB.addActionListener(new AppActionListener());
controlPanel.add(regJB);
addJB.addActionListener(new AppActionListener());
controlPanel.add(addJB);
updateJB.addActionListener(new AppActionListener());
controlPanel.add(updateJB);
removeJB.addActionListener(new AppActionListener());
controlPanel.add(removeJB);
exitJB.addActionListener(new AppActionListener());
controlPanel.add(exitJB);
this.add(controlPanel, BorderLayout.SOUTH);
this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public StoreGUI() {
this.setExtendedState(Frame.NORMAL);
thisFrame = this;
this.setTitle("Store");
this.pack();
this.setVisible(true);
thisFrame.setSize(600,600);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
c = getContentPane();
showGUI();
}
}
use setSize(width,height) on combo and list
ASKER
Neither of this works:
this.setLayout(new BorderLayout());
midPanel.setLayout(new FlowLayout());
userPanel.setLayout(new GridLayout(2,2));
combo.setSize(30, 30);
userPanel.add(combo);
userPanel.setSize(30, 30);
booklist.setVisibleRowCoun t(10);
JScrollPane pane = new JScrollPane(booklist);
userPanel.add(pane);
midPanel.add(userPanel);
this.add(midPanel, BorderLayout.CENTER);
this.setLayout(new BorderLayout());
midPanel.setLayout(new FlowLayout());
userPanel.setLayout(new GridLayout(2,2));
combo.setSize(30, 30);
userPanel.add(combo);
userPanel.setSize(30, 30);
booklist.setVisibleRowCoun
JScrollPane pane = new JScrollPane(booklist);
userPanel.add(pane);
midPanel.add(userPanel);
this.add(midPanel, BorderLayout.CENTER);
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.