Ask Experts Questions for FREE Help !
Ask

Forum to ask java question

Asked Jun 8, 2010, 07:09 AM — 1 Answer
Hi guys me working on swing in a project and I'm not understanding how me can get value from jList from one page to another page in jtextfield me using netbean



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* SalesOfGoodsGUI.java
*
* Created on Jun 7, 2010, 7:19:01 PM
*/
Package learn;

Import javax.swing.JList;

/**
*
* @author Vinay
*/
Public class SalesOfGoodsGUI extends javax.swing.JFrame {

/** Creates new form SalesOfGoodsGUI */
public SalesOfGoodsGUI() {
initComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

jScrollPane3 = new javax.swing.JScrollPane();
jTree1 = new javax.swing.JTree();
jScrollPane4 = new javax.swing.JScrollPane();
jEditorPane1 = new javax.swing.JEditorPane();
jCheckBox1 = new javax.swing.JCheckBox();
jLabel1 = new javax.swing.JLabel();
SetValueTextField = new javax.swing.JTextField();
InventoryLabel = new javax.swing.JLabel();
jScrollPane1 = new javax.swing.JScrollPane();
InventoryList = new javax.swing.JList();
FareLabel = new javax.swing.JLabel();
jScrollPane2 = new javax.swing.JScrollPane();
FareList = new javax.swing.JList();
SubmitButton = new javax.swing.JButton();
lblText = new javax.swing.JLabel();
lblTestValue = new javax.swing.JLabel();
FareSetLabel = new javax.swing.JLabel();

jScrollPane3.setViewportView(jTree1);

jScrollPane4.setViewportView(jEditorPane1);

jCheckBox1.setText("jCheckBox1");

jLabel1.setText("jLabel1");

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

InventoryLabel.setText("Inventory");

InventoryList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Car", "Byke", "Fruit", "Cold Drink", "Pizza" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane1.setViewportView(InventoryList);

FareLabel.setText("Fare");

FareList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "200000", "50000", "50", "12", "30" };
public int getSize() { return strings.length; }
public Object getElementAt(int i) { return strings[i]; }
});
jScrollPane2.setViewportView(FareList);

SubmitButton.setText("Submit");
SubmitButton.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
SubmitButtonActionPerformed(evt);
}
});

lblTestValue.setText("11111111");

FareSetLabel.setText("FareSet");

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(134, 134, 134)
.addComponent(SubmitButton)
.addContainerGap(566, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(68, 68, 68)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 501, Short.MAX_VALUE)
.addComponent(lblText)
.addGap(22, 22, 22))
.addGroup(layout.createSequentialGroup()
.addGap(166, 166, 166)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(FareSetLabel)
.addComponent(lblTestValue))
.addGap(309, 309, 309))))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblTestValue)
.addGap(57, 57, 57)
.addComponent(FareSetLabel)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addComponent(lblText))
.addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 49, Short.MAX_VALUE)
.addComponent(SubmitButton)
.addGap(115, 115, 115))))
);

pack();
}// </editor-fold>

private void SubmitButtonActionPerformed(java.awt.event.ActionE vent evt) {

ShowPage page = new ShowPage();
Object strInventory [] = this.InventoryList.getSelectedValues();
String strValue1 = "";
for (int I = 0; I < strInventory.length; i++) {
System.out.println(strInventory[i].toString());

if(i==0){
strValue1 = strInventory[i].toString();
}else{
strValue1 += "," + strInventory[i].toString();
}
}

page.setVisible(true);
this.lblTestValue.setText(strValue1);
//page.getContentPane().add(InventoryLabel);
page.getContentPane().add(InventoryLabel);
page.getContentPane().add(lblTestValue);


Object strFare [] = this.FareList.getSelectedValues();
String strValue2 = "";
for (int I = 0; I < strFare.length; i++) {
System.out.println(strFare[i].toString());

if(i==0){
strValue2 = strFare[i].toString();
}else{
strValue2 += "," + strFare[i].toString();
}

page.setVisible(true);
this.FareSetLabel.setText(strValue2);
page.getContentPane().add(FareLabel);
page.getContentPane().add(FareSetLabel);
//


//int j = FareList.getSelectedIndex();
// SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );


/*FareList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int j = FareList.getSelectedIndex();
SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );
}
});
return new JScrollPane( SetValueTextField ); */




}
//
//
}

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {

public void run() {
new SalesOfGoodsGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JLabel FareLabel;
private javax.swing.JList FareList;
private javax.swing.JLabel FareSetLabel;
private javax.swing.JLabel InventoryLabel;
private javax.swing.JList InventoryList;
private javax.swing.JTextField SetValueTextField;
private javax.swing.JButton SubmitButton;
private javax.swing.JCheckBox jCheckBox1;
private javax.swing.JEditorPane jEditorPane1;
private javax.swing.JLabel jLabel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JScrollPane jScrollPane4;
private javax.swing.JTree jTree1;
private javax.swing.JLabel lblTestValue;
private javax.swing.JLabel lblText;
// End of variables declaration
}

1 Answer
kishan.prajapati's Avatar
kishan.prajapati Posts: 2, Reputation: 10
New Member
 
#2

Jun 8, 2010, 07:18 AM
Hi guys me working on swing in a project and I'm not understanding how me can get value from jList from one page to another page in jtextfield me using netbean



/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* SalesOfGoodsGUI.java
*
* Created on Jun 7, 2010, 7:19:01 PM
*/
Package learn;

Import javax.swing.JList;

/**
*
* @author Vinay
*/
Public class SalesOfGoodsGUI extends javax.swing.JFrame {

/** Creates new form SalesOfGoodsGUI */
Public SalesOfGoodsGUI() {
InitComponents();
}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
Private void initComponents() {

JScrollPane3 = new javax.swing.JScrollPane();
JTree1 = new javax.swing.JTree();
JScrollPane4 = new javax.swing.JScrollPane();
JEditorPane1 = new javax.swing.JEditorPane();
JCheckBox1 = new javax.swing.JCheckBox();
JLabel1 = new javax.swing.JLabel();
SetValueTextField = new javax.swing.JTextField();
InventoryLabel = new javax.swing.JLabel();
JScrollPane1 = new javax.swing.JScrollPane();
InventoryList = new javax.swing.JList();
FareLabel = new javax.swing.JLabel();
JScrollPane2 = new javax.swing.JScrollPane();
FareList = new javax.swing.JList();
SubmitButton = new javax.swing.JButton();
LblText = new javax.swing.JLabel();
LblTestValue = new javax.swing.JLabel();
FareSetLabel = new javax.swing.JLabel();

JScrollPane3.setViewportView(jTree1);

JScrollPane4.setViewportView(jEditorPane1);

JCheckBox1.setText("jCheckBox1");

JLabel1.setText("jLabel1");

SetDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

InventoryLabel.setText("Inventory");

InventoryList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "Car", "Byke", "Fruit", "Cold Drink", "Pizza" };
Public int getSize() { return strings.length; }
Public Object getElementAt(int i) { return strings[i]; }
});
JScrollPane1.setViewportView(InventoryList);

FareLabel.setText("Fare");

FareList.setModel(new javax.swing.AbstractListModel() {
String[] strings = { "200000", "50000", "50", "12", "30" };
Public int getSize() { return strings.length; }
Public Object getElementAt(int i) { return strings[i]; }
});
JScrollPane2.setViewportView(FareList);

SubmitButton.setText("Submit");
SubmitButton.addActionListener(new java.awt.event.ActionListener() {
Public void actionPerformed(java.awt.event.ActionEvent evt) {
SubmitButtonActionPerformed(evt);
}
});

LblTestValue.setText("11111111");

FareSetLabel.setText("FareSet");

Javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
GetContentPane().setLayout(layout);
Layout.setHorizontalGroup(
Layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(134, 134, 134)
.addComponent(SubmitButton)
.addContainerGap(566, Short.MAX_VALUE))
.addGroup(layout.createSequentialGroup()
.addGap(68, 68, 68)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.TRAILING, false)
.addGroup(layout.createSequentialGroup()
.addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(50, 50, 50)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGroup(layout.createSequentialGroup()
.addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 501, Short.MAX_VALUE)
.addComponent(lblText)
.addGap(22, 22, 22))
.addGroup(layout.createSequentialGroup()
.addGap(166, 166, 166)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(FareSetLabel)
.addComponent(lblTestValue))
.addGap(309, 309, 309))))
);
Layout.setVerticalGroup(
Layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addContainerGap()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(InventoryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 46, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(33, 33, 33)
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(lblTestValue)
.addGap(57, 57, 57)
.addComponent(FareSetLabel)
.addContainerGap())
.addGroup(layout.createSequentialGroup()
.addGroup(layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(15, 15, 15)
.addComponent(lblText))
.addComponent(FareLabel, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 102, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.Component Placement.RELATED, 49, Short.MAX_VALUE)
.addComponent(SubmitButton)
.addGap(115, 115, 115))))
);

Pack();
}// </editor-fold>

Private void SubmitButtonActionPerformed(java.awt.event.ActionE vent evt) {

ShowPage page = new ShowPage();
Object strInventory [] = this.InventoryList.getSelectedValues();
String strValue1 = "";
For (int I = 0; I < strInventory.length; i++) {
System.out.println(strInventory[i].toString());

If(i==0){
StrValue1 = strInventory[i].toString();
}else{
StrValue1 += "," + strInventory[i].toString();
}
}

Page.setVisible(true);
This.lblTestValue.setText(strValue1);
//page.getContentPane().add(InventoryLabel);
Page.getContentPane().add(InventoryLabel);
Page.getContentPane().add(lblTestValue);


Object strFare [] = this.FareList.getSelectedValues();
String strValue2 = "";
For (int I = 0; I < strFare.length; i++) {
System.out.println(strFare[i].toString());

If(i==0){
StrValue2 = strFare[i].toString();
}else{
StrValue2 += "," + strFare[i].toString();
}

Page.setVisible(true);
This.FareSetLabel.setText(strValue2);
Page.getContentPane().add(FareLabel);
Page.getContentPane().add(FareSetLabel);
//


//int j = FareList.getSelectedIndex();
// SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );


/*FareList.addListSelectionListener(new ListSelectionListener() {
Public void valueChanged(ListSelectionEvent e) {
Int j = FareList.getSelectedIndex();
SetValueTextField.setText( j >= 0 ? StrValue2.get( j ) : "" );
}
});
Return new JScrollPane( SetValueTextField ); */




}
//
//
}

/**
* @param args the command line arguments
*/
Public static void main(String args[]) {
Java.awt.EventQueue.invokeLater(new Runnable() {

Public void run() {
New SalesOfGoodsGUI().setVisible(true);
}
});
}
// Variables declaration - do not modify
Private javax.swing.JLabel FareLabel;
Private javax.swing.JList FareList;
Private javax.swing.JLabel FareSetLabel;
Private javax.swing.JLabel InventoryLabel;
Private javax.swing.JList InventoryList;
Private javax.swing.JTextField SetValueTextField;
Private javax.swing.JButton SubmitButton;
Private javax.swing.JCheckBox jCheckBox1;
Private javax.swing.JEditorPane jEditorPane1;
Private javax.swing.JLabel jLabel1;
Private javax.swing.JScrollPane jScrollPane1;
Private javax.swing.JScrollPane jScrollPane2;
Private javax.swing.JScrollPane jScrollPane3;
Private javax.swing.JScrollPane jScrollPane4;
Private javax.swing.JTree jTree1;
Private javax.swing.JLabel lblTestValue;
Private javax.swing.JLabel lblText;
// End of variables declaration
}
___________________________
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/

/*
* ShowPage.java
*
* Created on Jun 8, 2010, 10:21:47 AM
*/

Package learn;

/**
*
* @author Vinay
*/
Public class ShowPage extends javax.swing.JFrame {

/** Creates new form ShowPage */
public ShowPage() {

initComponents();
setDefaultCloseOperation(javax.swing.
WindowConstants.DISPOSE_ON_CLOSE);
setTitle("Welcome");
setSize(400, 200);

}

/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {

SetValueTextField = new javax.swing.JTextField();

setDefaultCloseOperation(javax.swing.WindowConstan ts.EXIT_ON_CLOSE);

javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(87, 87, 87)
.addComponent(SetValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 201, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(112, Short.MAX_VALUE))
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout .Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addGap(88, 88, 88)
.addComponent(SetValueTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 74, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap(138, Short.MAX_VALUE))
);

pack();
}// </editor-fold>

/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new ShowPage().setVisible(true);
}
});
}

// Variables declaration - do not modify
private javax.swing.JTextField SetValueTextField;
// End of variables declaration

}
___________________
My no is 9015116841

And EmailId

kishan.prajapati@agnicient.com
Helpful

Not your question? Ask your question View similar questions

 
Thread Tools Search this Thread
Search this Thread:

Advanced Search

Add your answer here.

Remove Text Formatting

Undo
Redo
 
Decrease Size
Increase Size
Bold
Italic
Underline
Align Left
Align Center
Align Right
Ordered List
Unordered List
Decrease Indent
Increase Indent
Insert Email Link
Wrap [QUOTE] tags around selected text
Wrap [CODE] tags around selected text
Wrap [HTML] tags around selected text
Wrap [PHP] tags around selected text
Wrap [YOUTUBE] tags around selected text
Notification Type:



Check out some similar questions!

Three year old won't answer a question, he only repeats the question...any thoughts? [ 7 Answers ]

I have three children who have never had any learning troubles however I babysit 2 kids each day that seem to be a little socially awkward. The oldest (age 5 1/2) won't look me in the eye and can't follow a multi-step instruction. The younger (age 3) has never been able to answer a question I ask...

Java Help! [ 7 Answers ]

Hi Experts, I'm not sure if I'm posting this in the right category, but I sure hope someone can still help me. I'm not able to view Java applets. I've downloaded the most recent version of JVM. I have version 1.4.1. I've tried changing some settings (like enabling Java in my internet...


View more Java questions Search