venkat anand

Greenhorn
+ Follow
since Dec 23, 2004
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
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by venkat anand

HI Adrian,

I have 4th edition book for OOAD and patterns..Can i start going through it for my UML certificaiton or i need to follow only 2end edition book
Hi ranchers..would like to have your valuable help and suggestion..i am using jdk1.4.i have jtbale and would like to have one column data in sorted way..i don't want any other columns need to be done any thing.
just i am enclosing my code in tha i am using Collections.sort(data, new ColumnSorter(colIndex, ascending)); but that compare of that comparator is not at woring that data is not getting soretd.


Main java file:

/*
* Created on Jun 19, 2008
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.ibm.sort;

import java.awt.Dimension;
import java.awt.GridLayout;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.DefaultTableModel;

public class SimpleTableDemo extends JPanel {
private boolean DEBUG = false;
int colIndex;
boolean ascending;
DefaultTableModel model = new DefaultTableModel();
public SimpleTableDemo() {
super(new GridLayout(1,0));

String[] columnNames = {"First Name","Last Name","Sport","# of Years","Vegetarian"};

Object[][] data = {
{"Mary", "Campione","Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml", "Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath","Knitting", new Integer(2), new Boolean(false)},
{"Sharon", "Zakhour","Speed reading", new Integer(20), new Boolean(true)},
{"Philip", "Milne", "Pool", new Integer(10), new Boolean(false)}
};

final JTable table = new JTable(data, columnNames);
table.setPreferredScrollableViewportSize(new Dimension(500, 80));
table.setAutoCreateColumnsFromModel(false);
JScrollPane scrollPane = new JScrollPane(table);
add(scrollPane);

sortAllRowsBy(model, 1, true);
}

public void sortAllRowsBy(DefaultTableModel model, int colIndex, boolean ascending) {
Vector data = model.getDataVector();

System.out.println("SimpleTableDemo.sortAllRowsBy()11111");

Collections.sort(data, new ColumnSorter(colIndex, ascending));
//Collections.sort(data);


//Arrays.sort(data, new ColumnSorter(colIndex, ascending));
System.out.println("SimpleTableDemo.sortAllRowsBy()2222");
model.fireTableStructureChanged();
}





/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
private static void createAndShowGUI() {
//Create and set up the window.
JFrame frame = new JFrame("SimpleTableDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//Create and set up the content pane.
SimpleTableDemo newContentPane = new SimpleTableDemo();
newContentPane.setOpaque(true); //content panes must be opaque
frame.setContentPane(newContentPane);

//Display the window.
frame.pack();
frame.setVisible(true);
}

public static void main(String[] args) {
//Schedule a job for the event-dispatching thread:
//creating and showing this application's GUI.
javax.swing.SwingUtilities.invokeLater(new Runnable() {
public void run() {
createAndShowGUI();
}
});
}




}




*************

Second FIle which has sorting :

/*
* Created on Jun 21, 2008
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
package com.ibm.sort;

import java.util.Comparator;
import java.util.Vector;

// This comparator is used to sort vectors of data
public class ColumnSorter implements Comparator {
int colIndex;
boolean ascending;
ColumnSorter(int colIndex, boolean ascending) {
System.out.println("ColumnSorter.ColumnSorter(---colIndex--:"+colIndex+" ,ascending: "+ascending);

this.colIndex = colIndex;
this.ascending = ascending;
System.out.println("ColumnSorter.ColumnSorter()");
}
public int compare(Object a, Object b) {
System.out.println("compare-----:");
Vector v1 = (Vector)a;
Vector v2 = (Vector)b;
Object o1 = v1.get(colIndex);
Object o2 = v2.get(colIndex);
System.out.println("ColumnSorter.compare(): -o1- :"+o1+" ,o2: "+o2);
// Treat empty strains like nulls
if (o1 instanceof String && ((String)o1).length() == 0) {
o1 = null;
}
if (o2 instanceof String && ((String)o2).length() == 0) {
o2 = null;
}

// Sort nulls so they appear last, regardless
// of sort order
if (o1 == null && o2 == null) {
return 0;
} else if (o1 == null) {
return 1;
} else if (o2 == null) {
return -1;
} else if (o1 instanceof Comparable) {
if (ascending) {
System.out.println("ascending-->ColumnSorter.compare()-((Comparable)o1).compareTo(o2): "+(((Comparable)o1).compareTo(o2)));
return ((Comparable)o1).compareTo(o2);
} else {
System.out.println("Desending-->ColumnSorter.compare()-((Comparable)o1).compareTo(o2): "+(((Comparable)o1).compareTo(o2)));
return ((Comparable)o2).compareTo(o1);
}
} else {
if (ascending) {
System.out.println("ColumnSorter.compare()---o1.toString().compareTo(o2.toString())---: "+(o1.toString().compareTo(o2.toString())));
return o1.toString().compareTo(o2.toString());
} else {
return o2.toString().compareTo(o1.toString());
}
}
}
}


Please help is deadly needed.
thanks in advance!!!
9 years ago
Hi Ranchers,

I deadly need your help regarding the jtable .i am using jdk1.4 ..i stuck up at one requirement that ..i am have one column is editable in jtable..
When the end user enter some value (he will not hit enter or any key)just leave that cursor where the cell has been entered the value and hit update.but i am not getting that value..since focus is not been changed.
Could any one have any sample code or suggetions make me com out from this heard situation..Please help me.
10 years ago
Hi,

Deadly need ranchers help regarding the Jtable sorting and should have the check box in the JTable header and the header should have the multiline(might be 2 lines.I am really stuck up how to proceed.

I used the sorting the jtbale from one of the examples from the net i got name is: TableSorter.java,I am really new to this swings,Please help me in this regard .please share if any one is having code sample for this requirement.
your help greatly appreciated !! thanks
10 years ago
Hi Rob,,
Thanks for you reply..sorry,,i fogot to tell one thing that i Must use the JDK 1.4
10 years ago
I have Jtable with data and storting functionality with that.Sorting order is desc ,asc,normal(i used one i got from net is :TableSorter.java).When i click the header for sorting other than the normal i need to hide/remove one ROW (second column has value constant for that row) from my table,when it come to normal display i need to reinsert/unhide that deleted row?Suggestions are greatly appreciated.
Thanks
10 years ago
Deadly need your help..I am using jdk1.4 as per the requirement,
I stuck up where in my JTable i have lot of records..but the first column is having some category..some thing like for category1 have some records and category2 i have some records..when i try to sort on other columns i would like to have them sorted in that first column category wise.Thanks in advance
10 years ago
I am stuck up at one requirement is ..i need to display the same header after each set of 50 rows in the table and should able to sort the records when i click at any one of the headers.It is great help .
Thanks...
Venkat
10 years ago
Hi guys,

Planing to take the XML certification ,but bit confusion is which one need to take since we have Test 141 and Test 142,Greatly appreciated if you please clarify me of the difference and which one i need to take ?
Thanks inadvance!!!
Hi Theodore Jonathan Casser

Every body felt bore with the same question,How to prepare for the XML exam.I intend to know that.I know about the XML very little bit arround 1%.I would like to have some start up idea from you so that i feel comfortable to kick off the preparation.

One more thing is IBM is going to retire the test 141 XML certification.Now i am in dilemma whether i can start with the old syllabus.It is great favour if you send me some prescribed book name and your prepared meterial or some link regarding mock exams.
My mail id is :venkatxml@yahoo.co.in.
Hi,I would like to take up MQ Series Specialist.But i came to know that some administration exam is prerequisite.but i am totally confusing,what test i have to take.just i am working on java with MQ.
for this exam i could not have any resources and how to start up.
please any one help in this regard.
12 years ago
Hi key,

Thanks for sending me reply.

What you said is correct ,i completed SCJP and SCWCD,i came to know that by studying one book we can not complete.

Frankly asking you,is it needed working experience?.if you dont mind could you please send me the meterial what you are having or the liks to downd load.I will try my level best.
Could i expect you mail id.
key
Hi key,

Thanks for sending me reply.

What you said is correct ,i completed SCJP and SCWCD,i came to know that by studying one book we can not complete.

Frankly asking you,is it needed working experience?.if you dont mind could you please send me the meterial what you are having or the liks to downd load.I will try my level best.
Could i expect you mail id.
Hi guys,

I would like to prepare for webservices and i am dam fresher to this.Please guid me for meterial and good book to complete the certification in this.
my mail id is :sesha_anand@yahoo.com