Alberto Aparicio

Greenhorn
+ Follow
since Oct 01, 2010
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
(keep public parts private until JForum day)
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt
Moderation Tools

Recent posts by Alberto Aparicio


I tried to use this code in my javacode, but i'm not sure where i should put these code.
I put it in the method public TableDemo() {} but it does not work.
Can you tell me where exatly i should put these code and is these code you gave me complete or should i change it in a way?
I'm really a beginner with java,


7 years ago
Thank you for your fast reply!
You should know i'm from Holland, and my englisch is not so good, that's why i find it hard to explain what i mean.

On looking at your images, it still looks to me as if you want to use the selected row when the SEND JButton has been pressed. If this is indeed correct,

this is indeed correct! I only want the data in the row that has been changed, to be "send" to the TextArea.

don't use a TableModelListener but rather simply use the JButton's ActionListener and in the actionPerformed method, use the JTable's model to get the selected row and then to get the row data.


So i should not use TableModel listener. But i should only use the ActionPerformed method.
But how can i get the SELECTED row, and the row data in Actionperformed?
mayby you could give me an example in java code.
7 years ago
Here is the new code










Here are pictures from how the situation is now if i push the >SEND> button.
And a picture from how i want it to be.
7 years ago
I have lookt at TableModelListener and found a method called tablechanged!

public void tableChanged(TableModelEvent e) {
}



And some parameters from TableModelEvent

TableModelEvent(source); // The data, ie. all rows changed
TableModelEvent(source, HEADER_ROW); // Structure change, reallocate TableColumns
TableModelEvent(source, 1); // Row 1 changed
TableModelEvent(source, 3, 6); // Rows 3 to 6 inclusive changed
TableModelEvent(source, 2, 2, 6); // Cell at (2, 6) changed
TableModelEvent(source, 3, 6, ALL_COLUMNS, INSERT); // Rows (3, 6) were inserted
TableModelEvent(source, 3, 6, ALL_COLUMNS, DELETE); // Rows (3, 6) were deleted



Until so far i understand this theorie, but i don't know how i must use this method for my problem i described before.
my problem is this!


How can i make sure that only the data that is edited in a ROW, is printed (in the JTextArea).
I want the hole row to be printed. For example "Valk 10-10-2010 Gelderland 3 23".
The rows that are not edited must not be printed.



Mayby someone can give me some hints, because i'm really stuck here.
7 years ago
Thank you Michael, it worked well!

you'll still need to address:
if there are any conditions prior to printing the row's data e'g' if no date, ignore row
cell still in edit mode when 'send' pressed will print cell's pre-edit value



How can i make sure that only the data that is edited in a ROW, is printed (in the JTextArea).
I want the hole row to be printed. For example "Valk 10-10-2010 Gelderland 3 23".
The rows that are not used must not be printed.
7 years ago
Hello i'm really happy with Javaranch because without you i could never have come so far with my Java project for school.

Now i have another problem. I am making a registration form for "Bird Wathchers", they must fill in in the JTable how many birds they have seen on wich date.
After they push the send button the data must be transfered to the JTextArea. (Everytime you put new data on the JTextArea it must start on a new line.)
But it does not start on a new line.

Ill make a picture of how i want it to be, and how it is now. Maybe someone can help me with the code.



7 years ago
Thanks for all the help! i have learnt a lot. I have made the changes like Pete said.

but you must understand that i'm really not good at Java, but i have to do this project for my school.
So if you use a lot of theorie of Java, it's really dificult to understand for me. So i hope you have a little pattience with me.

But still nothing happens if i push the button. I want to copy the text from the Jtable to the JTextArea.

here is the NEW code mayby someone nows what i'm doing wrong.

if i push the button i get this error:

at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
at java.awt.EventDispatchThread.run(Unknown Source)


7 years ago
Thanks for al the help!

But now my program is advancing further, and getting more complex.

now i have a JTable 1button and 1 JTextArea. and the same problem as before.

My question is how can i get the button to put the text from the JTable to the JTextArea.

here is the new javacode!


----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


7 years ago

Maneesh Godbole wrote:I would recommend using JTextArea#append(String text) instead of concatenating and then setting the text.



I'v tried to use JTextArea#append(String text) in my Java code. But where exactly should i put JTextArea#append(String text)?
Can you give me an example, i only get a lot of ERRORS.

thanks

7 years ago
I've solved the problem by concatenate: veld5.setText(veldinhoud1 + veldinhoud2 + veldinhoud3 + veldinhoud4);.
Now it's working good.


I have another question??

How can i make sure the "previous" text in the JTextArea is not erased everytime i push the >Send> button.
My goal is to make a list in the "JTextArea".

I hope you understand my question, because my english is not so good!


7 years ago
Thanks for the help

But can you give me an example how i should concatenate the 4JTextFields.
I'm not sure where i should make the change in the java code.

7 years ago
Hello,

I'm a newby with Java.

I want to Copy text from 4 JTextFields, to 1 JTextArea, if i push the >Kopieer> button.
The problem is that only 1 JTextField is copieed to the JTextArea.
Does someone know how to resolve this problem.


------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
import javax.swing.*;

public class Invulscherm extends JFrame{

public Invulscherm(){

JFrame venster = new JFrame();
venster.setSize(700,240);
venster.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
venster.setTitle("Voorbeeld 1 van Telling");
venster.setLocation(100 ,100);
JPanel hoofdpaneel = new InvulschermPaneel();
venster.add(hoofdpaneel);
venster.setVisible(true);
}

public static void main( String[] args){
new Invulscherm();

}
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

import java.awt.event.*;
import javax.swing.*;

public class InvulschermPaneel extends JPanel implements ActionListener{

private JTextField veld1;
private JTextField veld2;
private JTextField veld3;
private JTextField veld4;
private JTextArea veld5;
private JButton actieknop;


public InvulschermPaneel(){
actieknop = new JButton(">SEND>");
actieknop.addActionListener(this);
veld1 = new JTextField(13);
veld2 = new JTextField(13);
veld3 = new JTextField(13);
veld4 = new JTextField(13);
veld5 = new JTextArea(3,40);

add(veld1);
add(veld2);
add(veld3);
add(veld4);
add(actieknop);
add(veld5);
}

public void actionPerformed(ActionEvent e){

String veldinhoud1 = veld1.getText();
String veldinhoud2 = veld2.getText();
String veldinhoud3 = veld3.getText();
String veldinhoud4 = veld4.getText();
veld5.setText(veldinhoud1);
veld5.setText(veldinhoud2);
veld5.setText(veldinhoud3);
veld5.setText(veldinhoud4);

}

}
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------

7 years ago