The Scenario
I'm doing a little project for my highschool programming class that entails creating the time tables for a volleyball tournament. The app will be placed on screen in a JFrame with two main JScrollPanes: one for the list of team names and one for the compiled time table.
The Problem
The list of team names will be displayed on screen with a JList inside of one of the mentioned JScrollPanes. When the app is started, there is nothing in the list. I want to be able to update the list on screen when the actual list of names is changed through some event (say, clicking a button). I can update the JList in my class easily enough, I just can't figure out how to make the screen correspond to these changes, atleast without removing the old one entirely and adding the new one to the content pane (which would make my head hurt).
Here's what I have so far:
I've simplified the JList for now. I've only dealt with the teams list so far, but I suspect that I'll have the same problem with the time table.
Yes, I am a newb.
I'm doing a little project for my highschool programming class that entails creating the time tables for a volleyball tournament. The app will be placed on screen in a JFrame with two main JScrollPanes: one for the list of team names and one for the compiled time table.
The Problem
The list of team names will be displayed on screen with a JList inside of one of the mentioned JScrollPanes. When the app is started, there is nothing in the list. I want to be able to update the list on screen when the actual list of names is changed through some event (say, clicking a button). I can update the JList in my class easily enough, I just can't figure out how to make the screen correspond to these changes, atleast without removing the old one entirely and adding the new one to the content pane (which would make my head hurt).
Here's what I have so far:
Code:
package tournament.app;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class TourneyApp implements ActionListener {
private JFrame appFrame;
private JPanel teamsPanel;
private JList teamsList;
private JScrollPane teamsPane;
public TourneyApp() {
appFrame = new JFrame( "Tournament TimeTable App Ver 1.0" );
appFrame.addWindowListener(new WindowAdapter() {
public void windowClosing( WindowEvent we ) { System.exit(0); }
});
teamsPanel = new JPanel();
teamsPanel.setPreferredSize(new Dimension(300, 200));
teamsList = new JList(new String [] { "uno", "dos", "tres" });
teamsPane = new JScrollPane(teamsList);
teamsPanel.add(teamsPane);
JButton testButton = new JButton("bork");
testButton.addActionListener(this);
teamsPanel.add(testButton);
testButton = new JButton("!bork");
testButton.addActionListener(this);
teamsPanel.add(testButton);
appFrame.getContentPane().add(teamsPanel);
appFrame.pack();
appFrame.setLocation(100, 100);
appFrame.setVisible(true);
}
public void actionPerformed( ActionEvent e ) {
if(e.getActionCommand().equals("bork")) {
teamsList = new JList(new String [] { "uno", "dos", "tres", "bork" });
teamsPane = new JScrollPane(teamsList);
appFrame.repaint();
}
if(e.getActionCommand().equals("!bork")) {
teamsList = new JList(new String [] { "uno", "dos", "tres", "!bork" });
teamsPane = new JScrollPane(teamsList);
appFrame.repaint();
}
}
public static void main( String [] args ) {
new TourneyApp();
}
}
I've simplified the JList for now. I've only dealt with the teams list so far, but I suspect that I'll have the same problem with the time table.
Yes, I am a newb.