Re: Help with Swing
RedGrittyBrick wrote:
GG Sriram wrote:
//Incomplete
}
Incomplete - -
Yes, that makes it hard to help. It demotivates helpers.
Why can't I resist this sort of foolishness?
----------------------------------- 8< -----------------------------
public class ZzzMadGUI implements ActionListener {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
new ZzzMadGUI();
}
});
}
enum Actions {
UP, DOWN, DELETE
}
ZzzMadGUI() {
final Box box = Box.createHorizontalBox();
final JButton b1 = new JButton ("Add First");
b1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
b1.setEnabled(false);
b1.setVisible(false);
for (Actions a : Actions.values()) {
JButton b = new JButton(a.name());
b.addActionListener(this);
box.add(b);
}
}});
box.add(b1);
JPanel p = new JPanel(new BorderLayout());
JLabel l = new JLabel("Other Widgets go here, maybe a JTable");
p.add(l, BorderLayout.CENTER);
p.add(box, BorderLayout.NORTH);
JFrame f = new JFrame("ZzzMadGUI");
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
f.pack();
f.setLocationRelativeTo(null);
f.setVisible(true);
}
public void actionPerformed(ActionEvent e) {
switch (Actions.valueOf(e.getActionCommand())) {
case UP:
break;
case DOWN:
break;
case DELETE:
break;
default:
// log, tell user and die horribly
}
}
}
----------------------------------- 8< -----------------------------
Personally I'd have all buttons visible but just enable and disable
appropriate ones according to the state of the application. Disabled
buttons look disabled and users expect that sort of thing.
I'd expect users to be confused by having buttons magically appear and
disappear. YMMV.
If none of the above bears any relation to what you are trying to
achieve, frankly its because you have failed to adequately explain or
provide a runnable example.
--
RGB