Here is some code:
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(this);
and then:
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
a();
}
}
public class ViewDeclinedRequests extends MainMenu {
private String[] columnNames = {"REQUEST ID", "STATUS", "BANK NAME", "EMPLOYEE FIRST NAME", "EMPLOYEE LAST NAME", "CURRENCY REQUESTED", "AMOUNT REQUESTED", "CURRENCY OFFERED", "AMOUNT OFFERED", "TIME REQUESTED", "DATE REQUESTED"};
private Object[][] data = new Object [50] [50];
private JTable table = new JTable(data, columnNames);
private JScrollPane scrollPane = new JScrollPane(table);
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(table);
public ViewDeclinedRequests() {
//code here
}
//
method where GUI is constructed
public void assembleComponnents() {
}
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting())
{
}
}
}
no neither of those worked
i know u probably dont wanna see this but i am gonna post all the cde maybe u can see something wrong with it
package GUI;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;
import java.awt.color.*;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.event.*;
import Database.*;
import java.util.EventObject.*;
/**
* Represent the Create New Customer menu screen.
*
* @author Neroo Technologies
* @version 14-03-06
*/
public class ViewDeclinedRequests extends MainMenu implements ListSelectionListener{
// instance variables
private static final Font MEDIUM_FONT = new Font("Times New Roman", Font.BOLD, 28);
private static final Font SMALL_FONT = new Font("Times New Roman", Font.BOLD, 13);
private static final Font REGULAR_FONT = new Font("Arial", Font.PLAIN, 11);
private JLabel titleLabel = new JLabel("VIEW DECLINED");
private JLabel titleLabel2 = new JLabel("REQUESTS");
private JLabel selectionLabel = new JLabel("SELECTION");
private JLabel messageLabel = new JLabel("MESSAGE:");
private JButton returnToMainMenuButton = new JButton(" Return To Main Menu ");
public JButton helpButton = new JButton("HELP");
private JLabel employeeDetailsLabel = new JLabel("COMPLETED REQUESTS");
private JTextArea messageArea = new JTextArea();
private JPanel matchDetailsPanel = new JPanel();
private String[] columnNames = {"REQUEST ID", "STATUS", "BANK NAME", "EMPLOYEE FIRST NAME", "EMPLOYEE LAST NAME", "CURRENCY REQUESTED", "AMOUNT REQUESTED", "CURRENCY OFFERED", "AMOUNT OFFERED", "TIME REQUESTED", "DATE REQUESTED"};
private Object[][] data = new Object [50] [50];
private JTable table = new JTable(data, columnNames);
private JScrollPane scrollPane = new JScrollPane(table);
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(this);
private Date date = new Date();
private Date time = new Date();
private String name;
private String employeeID;
private String userName;
private String bankName;
private String bankID;
private String totalRequested;
/*
* Constructor for EditExistingUserAccount
*/
public ViewDeclinedRequests() {
super();
setSize(800,705);
// Place the frame at the center of the screen
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(d.width/2 - this.getWidth()/2, d.height/2 - this.getHeight()/2);
setVisible(true);
name = "";
employeeID = "";
userName = "";
bankName = "";
bankID = "";
totalRequested = "";
//System.out.println(name + "...." + employeeID + "...." + userName);
}
/*
* Assemble all componnents together by adding them to the container
*/
public void assembleComponnents() {
// Set the Content Pane to have a Border Layout
Container contentPane = this.getContentPane();
contentPane.setLayout(null);
// Get the pixel coordinates of the panel edges
Insets insets = contentPane.getInsets();
// Set font size and colour to texts, then add them to contentPane
titleLabel.setFont(MEDIUM_FONT);
titleLabel.setForeground(new Color(200, 10, 50));
contentPane.add(titleLabel);
titleLabel2.setFont(MEDIUM_FONT);
titleLabel2.setForeground(new Color(200, 10, 50));
contentPane.add(titleLabel2);
employeeDetailsLabel.setFont(SMALL_FONT);
employeeDetailsLabel.setForeground(new Color(200, 10, 50));
contentPane.add(employeeDetailsLabel);
messageLabel.setFont(SMALL_FONT);
messageLabel.setForeground(new Color(200, 10, 50));
contentPane.add(messageLabel);
messageArea.setFont(REGULAR_FONT);
contentPane.add(messageArea);
contentPane.add(scrollPane);
table.setPreferredScrollableViewportSize(new Dimension(695, 150));
scrollPane.getVerticalScrollBar().setUnitIncrement(10);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
matchDetailsPanel.setBorder(new LineBorder(new Color(200, 10, 50), 1));
contentPane.add(matchDetailsPanel);
matchDetailsPanel.setLayout(null);
// Set date and time
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
JLabel dateLabel = new JLabel(df.format(date));
contentPane.add(dateLabel);
DateFormat tf = DateFormat.getTimeInstance(DateFormat.DEFAULT);
JLabel timeLabel = new JLabel(tf.format(time));
contentPane.add(timeLabel);
// Add buttons to contentPane
contentPane.add(helpButton);
contentPane.add(returnToMainMenuButton);
displayValues();
Dimension size;
// Fix date label position
size = dateLabel.getPreferredSize();
dateLabel.setBounds(700 + insets.left, 20 + insets.top, size.width, size.height);
// Fix time label position
size = timeLabel.getPreferredSize();
timeLabel.setBounds(700 + insets.left, 40 + insets.top, size.width, size.height);
// Fix title label position
size = titleLabel.getPreferredSize();
titleLabel.setBounds(310 + insets.left, 30 + insets.top, size.width, size.height);
// Fix title label 2 position
size = titleLabel2.getPreferredSize();
titleLabel2.setBounds(365 + insets.left, 60 + insets.top, size.width, size.height);
// Fix account holder name label position
size = employeeDetailsLabel.getPreferredSize();
employeeDetailsLabel.setBounds(40 + insets.left, 85 + insets.top, size.width, size.height);
// Fix title label 2 position
size = matchDetailsPanel.getPreferredSize();
matchDetailsPanel.setBounds(30 + insets.left, 110 + insets.top, size.width + 730, size.height + 420);
// Fix table's scrollpane position
size = scrollPane.getPreferredSize();
scrollPane.setBounds(40 + insets.left, 120 + insets.top, size.width, size.height + 100);
// Fix table's scrollpane position
size = messageLabel.getPreferredSize();
messageLabel.setBounds(40 + insets.left, 410 + insets.top, size.width, size.height);
// Fix table's scrollpane position
size = messageArea.getPreferredSize();
messageArea.setBounds(40 + insets.left, 430 + insets.top, size.width + 710, size.height + 70);
// Fix return to main menu button position
size = returnToMainMenuButton.getPreferredSize();
returnToMainMenuButton.setBounds(625 + insets.left, 601 + insets.top, size.width, size.height);
// Fix help button position
size = helpButton.getPreferredSize();
helpButton.setBounds(15 + insets.left, 601 + insets.top, size.width, size.height);
setVisible(true);
populateTable();
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(table);
// public void valueChanged(ListSelectionEvent e) {
// if (!e.getValueIsAdjusting())
// {
//
// }
//}
helpButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
}
});
returnToMainMenuButton.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
MainMenu mMenu = new MainMenu();
mMenu.assembleComponnents();
setVisible(false);
}
});
}
private void populateTable() {
TableColumn column = null;
for (int i = 0; i < 11; i++)
{
column = table.getColumnModel().getColumn(i);
if (i == 0)
{
column.setPreferredWidth(100);
}
if (i == 1)
{
column.setPreferredWidth(100);
}
if (i == 2)
{
column.setPreferredWidth(100);
}
if (i == 3)
{
column.setPreferredWidth(175);
}
if (i == 4)
{
column.setPreferredWidth(175);
}
if (i == 5)
{
column.setPreferredWidth(160);
}
if (i == 6)
{
column.setPreferredWidth(150);
}
if (i == 7)
{
column.setPreferredWidth(150);
}
if (i == 8)
{
column.setPreferredWidth(130);
}
if (i == 9)
{
column.setPreferredWidth(150);
}
if (i == 10)
{
column.setPreferredWidth(150);
}
}
}
private void displayValues() {
AccountQueries aQueries = new AccountQueries();
String bName = aQueries.queryBrokerName(currentLoggedUser);
System.out.println(bName + "......" + currentLoggedUser);
RequestQueries rQueries = new RequestQueries();
if (rQueries.completedSize(bName) > 0)
{
String output = rQueries.queryDeclined(bName);
System.out.println(output);
String [] valuesArray = output.split("/n");
int index = 0;
if (valuesArray.length > index)
{
int col = 0;
int row = 0;
while (col < 11)
{
table.setValueAt(valuesArray[index], row, col);
index++;
col++;
}
row++;
col = 0;
}
}
else
{
{
JOptionPane.showMessageDialog(
null,
"There are no Completed Requests\n" +
"\n",
"NO COMPLETED REQUESTS",
JOptionPane.INFORMATION_MESSAGE);
}
MainMenu mMenu = new MainMenu();
mMenu.assembleComponnents();
setVisible(false);
}
}
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(this);
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting())
{
}
}
}
eum I see that you at the bottom of the code you again do
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(this);
this lines must be deleted!
And if than the program not work look at what line the error is occuring?
Or give here the error what is presenting.
Satanduvel
Try this one dude:
package GUI;
import java.awt.*;
import javax.swing.*;
import java.util.*;
import java.text.*;
import java.awt.event.*;
import java.awt.color.*;
import javax.swing.border.*;
import javax.swing.table.*;
import javax.swing.event.*;
import Database.*;
import java.util.EventObject.*;
/**
* Represent the Create New Customer menu screen.
*
* @author Neroo Technologies
* @version 14-03-06
*/
public class ViewDeclinedRequests extends MainMenu implements
ListSelectionListener {
// instance variables
private static final Font MEDIUM_FONT = new Font("Times New Roman",
Font.BOLD, 28);
private static final Font SMALL_FONT = new Font("Times New Roman",
Font.BOLD, 13);
private static final Font REGULAR_FONT = new Font("Arial", Font.PLAIN, 11);
private JLabel titleLabel = new JLabel("VIEW DECLINED");
private JLabel titleLabel2 = new JLabel("REQUESTS");
private JLabel selectionLabel = new JLabel("SELECTION");
private JLabel messageLabel = new JLabel("MESSAGE:");
private JButton returnToMainMenuButton = new JButton(
" Return To Main Menu ");
public JButton helpButton = new JButton("HELP");
private JLabel employeeDetailsLabel = new JLabel("COMPLETED REQUESTS");
private JTextArea messageArea = new JTextArea();
private JPanel matchDetailsPanel = new JPanel();
private String[] columnNames = { "REQUEST ID", "STATUS", "BANK NAME",
"EMPLOYEE FIRST NAME", "EMPLOYEE LAST NAME", "CURRENCY REQUESTED",
"AMOUNT REQUESTED", "CURRENCY OFFERED", "AMOUNT OFFERED",
"TIME REQUESTED", "DATE REQUESTED" };
private Object[][] data = new Object[50][50];
private JTable table = new JTable(data, columnNames);
private JScrollPane scrollPane = new JScrollPane(table);
private Date date = new Date();
private Date time = new Date();
private String name;
private String employeeID;
private String userName;
private String bankName;
private String bankID;
private String totalRequested;
/*Delete this eh?
* Constructor for EditExistingUserAccount
*/
public ViewDeclinedRequests() {
//What are you sending to the parent constructor?
super();
setSize(800, 705);
// Place the frame at the center of the screen
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation(d.width / 2 - this.getWidth() / 2, d.height / 2
- this.getHeight() / 2);
setVisible(true);
name = "";
employeeID = "";
userName = "";
bankName = "";
bankID = "";
totalRequested = "";
// System.out.println(name + "...." + employeeID + "...." + userName);
}
/*
* Assemble all componnents together by adding them to the container
*/
public void assembleComponents() {
// Set the Content Pane to have a Border Layout
Container contentPane = this.getContentPane();
contentPane.setLayout(null);
// Get the pixel coordinates of the panel edges
Insets insets = contentPane.getInsets();
// Set font size and colour to texts, then add them to contentPane
titleLabel.setFont(MEDIUM_FONT);
titleLabel.setForeground(new Color(200, 10, 50));
contentPane.add(titleLabel);
titleLabel2.setFont(MEDIUM_FONT);
titleLabel2.setForeground(new Color(200, 10, 50));
contentPane.add(titleLabel2);
employeeDetailsLabel.setFont(SMALL_FONT);
employeeDetailsLabel.setForeground(new Color(200, 10, 50));
contentPane.add(employeeDetailsLabel);
messageLabel.setFont(SMALL_FONT);
messageLabel.setForeground(new Color(200, 10, 50));
contentPane.add(messageLabel);
messageArea.setFont(REGULAR_FONT);
contentPane.add(messageArea);
contentPane.add(scrollPane);
table.setPreferredScrollableViewportSize(new Dimension(695, 150));
scrollPane.getVerticalScrollBar().setUnitIncrement(10);
table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
matchDetailsPanel.setBorder(new LineBorder(new Color(200, 10, 50), 1));
contentPane.add(matchDetailsPanel);
matchDetailsPanel.setLayout(null);
// Set date and time
DateFormat df = DateFormat.getDateInstance(DateFormat.SHORT);
JLabel dateLabel = new JLabel(df.format(date));
contentPane.add(dateLabel);
DateFormat tf = DateFormat.getTimeInstance(DateFormat.DEFAULT);
JLabel timeLabel = new JLabel(tf.format(time));
contentPane.add(timeLabel);
// Add buttons to contentPane
contentPane.add(helpButton);
contentPane.add(returnToMainMenuButton);
displayValues();
Dimension size;
// Fix date label position
size = dateLabel.getPreferredSize();
dateLabel.setBounds(700 + insets.left, 20 + insets.top, size.width,
size.height);
// Fix time label position
size = timeLabel.getPreferredSize();
timeLabel.setBounds(700 + insets.left, 40 + insets.top, size.width,
size.height);
// Fix title label position
size = titleLabel.getPreferredSize();
titleLabel.setBounds(310 + insets.left, 30 + insets.top, size.width,
size.height);
// Fix title label 2 position
size = titleLabel2.getPreferredSize();
titleLabel2.setBounds(365 + insets.left, 60 + insets.top, size.width,
size.height);
// Fix account holder name label position
size = employeeDetailsLabel.getPreferredSize();
employeeDetailsLabel.setBounds(40 + insets.left, 85 + insets.top,
size.width, size.height);
// Fix title label 2 position
size = matchDetailsPanel.getPreferredSize();
matchDetailsPanel.setBounds(30 + insets.left, 110 + insets.top,
size.width + 730, size.height + 420);
// Fix table's scrollpane position
size = scrollPane.getPreferredSize();
scrollPane.setBounds(40 + insets.left, 120 + insets.top, size.width,
size.height + 100);
// Fix table's scrollpane position
size = messageLabel.getPreferredSize();
messageLabel.setBounds(40 + insets.left, 410 + insets.top, size.width,
size.height);
// Fix table's scrollpane position
size = messageArea.getPreferredSize();
messageArea.setBounds(40 + insets.left, 430 + insets.top,
size.width + 710, size.height + 70);
// Fix return to main menu button position
size = returnToMainMenuButton.getPreferredSize();
returnToMainMenuButton.setBounds(625 + insets.left, 601 + insets.top,
size.width, size.height);
// Fix help button position
size = helpButton.getPreferredSize();
helpButton.setBounds(15 + insets.left, 601 + insets.top, size.width,
size.height);
setVisible(true);
populateTable();
ListSelectionModel listMod = table.getSelectionModel();
listMod.addListSelectionListener(this);
helpButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
}
});
returnToMainMenuButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
MainMenu mMenu = new MainMenu();
mMenu.assembleComponents();
//are you setting the ActionListener to invisible?
setVisible(false);
}
});
}
private void populateTable() {
TableColumn column = null;
for (int i = 0; i < 11; i++) {
column = table.getColumnModel().getColumn(i);
if (i == 0) {
column.setPreferredWidth(100);
}
if (i == 1) {
column.setPreferredWidth(100);
}
if (i == 2) {
column.setPreferredWidth(100);
}
if (i == 3) {
column.setPreferredWidth(175);
}
if (i == 4) {
column.setPreferredWidth(175);
}
if (i == 5) {
column.setPreferredWidth(160);
}
if (i == 6) {
column.setPreferredWidth(150);
}
if (i == 7) {
column.setPreferredWidth(150);
}
if (i == 8) {
column.setPreferredWidth(130);
}
if (i == 9) {
column.setPreferredWidth(150);
}
if (i == 10) {
column.setPreferredWidth(150);
}
}
}
private void displayValues() {
AccountQueries aQueries = new AccountQueries();
String bName = aQueries.queryBrokerName(currentLoggedUser);
System.out.println(bName + "......" + currentLoggedUser);
RequestQueries rQueries = new RequestQueries();
if (rQueries.completedSize(bName) > 0) {
String output = rQueries.queryDeclined(bName);
System.out.println(output);
String[] valuesArray = output.split("/n");
int index = 0;
if (valuesArray.length > index) {
int col = 0;
int row = 0;
while (col < 11) {
table.setValueAt(valuesArray[index], row, col);
index++;
col++;
}
row++;
col = 0;
}
} else {
//Why is this in a code block?
{
JOptionPane.showMessageDialog(null,
"There are no Completed Requests\n" + "\n",
"NO COMPLETED REQUESTS",
JOptionPane.INFORMATION_MESSAGE);
}
MainMenu mMenu = new MainMenu();
//Does a MainMenu Object contain the method assembleComponents?
//Because it is declared locally in this class.
//Maybe you mean:
//MainMenu mMenu = new ViewDeclinedRequests();
mMenu.assembleComponents();
setVisible(false);
}
}
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
}
}
}
Swing related questions should be posted in the Swing forum.
> i know u probably dont wanna see this but i am gonna post all the cde maybe u can see something wrong with it
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program[/url] (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags[/url] so the posted code retains its original formatting.