NIKHIL EROS

Greenhorn
+ Follow
since Sep 21, 2001
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by NIKHIL EROS

hi Dan,
can u be please more illustrative in ur problem. the problem on threads, in particular event despatch threads need more care and understanding of concepts.
please explain ur problem in more convenient way!!
regards
Nikhil.
compile and run this...
import javax.swing.JTable;
import javax.swing.table.AbstractTableModel;
import javax.swing.DefaultCellEditor;
import javax.swing.JScrollPane;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;
import java.awt.*;
import java.awt.event.*;
public class TableEditDemo extends JFrame {
private boolean DEBUG = true;
public TableEditDemo() {
super("TableEditDemo");
MyTableModel myModel = new MyTableModel();
JTable table = new JTable(myModel);
table.setPreferredScrollableViewportSize(new Dimension(500, 70));
//Create the scroll pane and add the table to it.
JScrollPane scrollPane = new JScrollPane(table);
//Set up real input validation for the integer column.
setUpIntegerEditor(table);
//Add the scroll pane to this window.
getContentPane().add(scrollPane, BorderLayout.CENTER);
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
}
private void setUpIntegerEditor(JTable table) {
//Set up the editor for the integer cells.
final WholeNumberField integerField = new WholeNumberField(0, 5);
integerField.setHorizontalAlignment(WholeNumberField.RIGHT);
DefaultCellEditor integerEditor =
new DefaultCellEditor(integerField) {
//Override DefaultCellEditor's getCellEditorValue method
//to return an Integer, not a String:
public Object getCellEditorValue() {
return new Integer(integerField.getValue());
}
};
table.setDefaultEditor(Integer.class, integerEditor);
}
class MyTableModel extends AbstractTableModel {
final String[] columnNames = {"First Name",
"Last Name",
"Sport",
"# of Years",
"Vegetarian"};
final Object[][] data = {
{"Mary", "Campione",
"Snowboarding", new Integer(5), new Boolean(false)},
{"Alison", "Huml",
"Rowing", new Integer(3), new Boolean(true)},
{"Kathy", "Walrath",
"Chasing toddlers", new Integer(2), new Boolean(false)},
{"Mark", "Andrews",
"Speed reading", new Integer(20), new Boolean(true)},
{"Angela", "Lih",
"Teaching high school", new Integer(4), new Boolean(false)}
};
public int getColumnCount() {
return columnNames.length;
}

public int getRowCount() {
return data.length;
}
public String getColumnName(int col) {
return columnNames[col];
}
public Object getValueAt(int row, int col) {
return data[row][col];
}
/*
* JTable uses this method to determine the default renderer/
* editor for each cell. If we didn't implement this method,
* then the last column would contain text ("true"/"false"),
* rather than a check box.
*/
public Class getColumnClass(int c) {
return getValueAt(0, c).getClass();
}
/*
* Don't need to implement this method unless your table's
* editable.
*/
public boolean isCellEditable(int row, int col) {
//Note that the data/cell address is constant,
//no matter where the cell appears onscreen.
if (col < 2) {
return false;
} else {
return true;
}
}
public void setValueAt(Object value, int row, int col) {
if (DEBUG) {
System.out.println("Setting value at " + row + "," + col
+ " to " + value
+ " (an instance of "
+ value.getClass() + ")");
}
data[row][col] = value;
fireTableCellUpdated(row, col);
if (DEBUG) {
System.out.println("New value of data:");
printDebugData();
}
}
private void printDebugData() {
int numRows = getRowCount();
int numCols = getColumnCount();
for (int i=0; i < numRows; i++) {
System.out.print(" row " + i + ":");
for (int j=0; j < numCols; j++) {
System.out.print(" " + data[i][j]);
}
System.out.println();
}
System.out.println("--------------------------");
}
}
public static void main(String[] args) {
TableEditDemo frame = new TableEditDemo();
frame.pack();
frame.setVisible(true);
}
}
i hope it clarifies ur doubt...that for showing check boxes in table u just need to have boolean values in the table.
u need to override the renderer class only when u want to customixe the way the cells in the table r presented !!
[This message has been edited by NIKHIL EROS (edited November 21, 2001).]
23 years ago
after exploring java docs, i could learn how to disable the close button on JFrame, but i could not get anywhere as "How to disable the minimize button on JFrame" ??
can anbody please guide me the way to achieve that?
23 years ago
My tree is coming collapsed when i run my application, i have tried using functions like expandRow(int), setExpandedState(Treepath, boolean), but it doesn't work.
Also if i use setExpandedState(Treepath, boolean) function, then in collapsed state Treepath argument will be null, so there is no point in using it.
please help me!!
thanks in advance.
23 years ago
I am using JDesktopPane and JInternalFrame. I have set the layout of JDesktopPane to an instance of FlowLayout.
The problem is when i minimize or iconize my JInternalFrames, they get scattered all over the desktop area, i want they should come minimized at the bottom of JDesktopPane, instead of all over the JDesktopPane, as they should ideally be !!
please suggest me what should i do??
thanks in advance.
23 years ago
i have made a desktop application using JDesktop and JInternalFrame classes, this desktop is placed in a JSpiltPane. the problem is when i minimize the internal frames, they r scattered over the desktop, they should appear aligned at the bottom of the dektop as ideally should be.
i have alreay used setNormalBounds() of JInternalFrame but of no use. can anybody please help me out, so that they come aligned at the bottom of desktop??
thanks in advance,
23 years ago

hi,
I think u should take help of the interface called VetoableChangeListener. ur JInternalFrame class extension should implement this interface and add this listener using addVetoableChangeListener() method. this listener "vetoes" the closing of JInternalFrame if customized to do so.
explore it!!
hope it helps u.
regards
Nikhil.
23 years ago
i want that when i iconize or minimize a JInternalFrame window on taskbar, bases on certain condition its minimized icon should change its colour or looks (like in yahoo messenger, when a message comes, the minimized or iconized instant message window blinks!!)
is there any class available for such customizations?? how should i achieve this?
thanks in advance
23 years ago
i m displaying my tree by extending DefaultTreeCellRenderer..
and using my own class called FriendInfo for the construction of DefaultMutableTreeNode for the tree....
private class MyRenderer extends DefaultTreeCellRenderer {
ImageIcon availableIcon;
ImageIcon offlineIcon;
ImageIcon awayIcon;
ImageIcon awayPendingIcon;
public MyRenderer() {
availableIcon = new ImageIcon("images/Available.gif");
offlineIcon = new ImageIcon("images/Offline.gif");
awayIcon = new ImageIcon("images/Away.gif");
awayPendingIcon = new ImageIcon("images/AwayPending.gif");
}
public Component getTreeCellRendererComponent(
JTree tree,
Object value,
boolean sel,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
super.getTreeCellRendererComponent(
tree, value, sel,
expanded, leaf, row,
hasFocus);
int holdStatus = whatStatus(value);
if (leaf && (holdStatus == 1)) {
setIcon(availableIcon);
setToolTipText("This friend is online");
}
if (leaf && (holdStatus == 2)) {
setIcon(offlineIcon);
setToolTipText("This friend is offline");
}
if (leaf && (holdStatus == 3)) {
setIcon(awayIcon);
setToolTipText("This friend is away");
}
if (leaf && (holdStatus == 4)) {
setIcon(awayPendingIcon);
setToolTipText("This friend is away pending");
}

return this;
}
protected int whatStatus(Object value) {
DefaultMutableTreeNode node =
(DefaultMutableTreeNode)value;
FriendInfo nodeInfo =
(FriendInfo)(node.getUserObject());//<--error
//System.out.println(nodeInfo.toString());
String status = nodeInfo.status;
if(status.equals("Available")){
return 1;
}
if(status.equals("Offline")){
return 2;
}
if(status.equals("Away")){
return 3;
}
if(status.equals("AwayPending")){
return 4;
}
return 0;
}
}
}
//------------------------------------------------------------------------
class FriendInfo {
public String friendName;
public String status;
public FriendInfo(String friendName, String status) {
this.friendName = friendName;
this.status = status;
}
public String toString() {
return (friendName + " (" + status + ")");
}
}
//---------------------------------------------------------------
at run time it is giving "ClassCastException: Java.lang.String" at the line marked above in the code in whatStatus() method of my MyRenderer class...
i have wasted several hours of mine in getting help from books and java sun site, but i could not solve the problem..
please help me..
23 years ago
when we use thin driver to connect to oracle database
Connection conn = DriverManager.getConnection
("jdbc racle:thin:@host ort:sid",
"scott", "tiger");
I COULD NOT UNDERSTAND WHAT ARE......
"host"
"port"
"sid"
IN ABOVE FUNTION.
Please help me
i m using a JTree and JComboBox in my code. I want everytime a user makes a certain selection in checkboxes, the tree component and comboxbox component should be REPOPULATED.
for creating new node structure for JTree and String[] for ComboBox my code is ready.
can anybody please help me how should i take care of REPAINTING OR REVALIDATING OR RELOADING the JTree and JComboBox Components, everytime i want to REPOPULATE them??
thanks in advance
[This message has been edited by NIKHIL EROS (edited October 10, 2001).]
23 years ago
i m developing a chat application using JDesktopPane and JInternalFrame, in which , i want that when a new message comes, my iconised JInternalFrame at taskbar should blink in a different colour like usual proffessional chat services. How should i do this using the custom JInternalFrame class methods??
please help me to implement this idea!!!
regards
Nikhil.
[This message has been edited by NIKHIL EROS (edited October 09, 2001).]
23 years ago
i have three classes namely class All, class B and class C.
for simplicity in asking my doubt, i m not showing the actual lengthy code but just a representation and define them as follows..
class All {
B b;
C c;

public All() {
b = new B();
}
//other work
}
class B {
C c;
public B() {
c = new C();
}
//other work
}
class C {
void CMethod(){
//method
}
//some class work
}
i want to know when the object of class All is formed and its constructor is invoked so that this object of class All contains a reference 'b' to an object of class B, how can i make the reference variable 'c' of type C, contained in class All, point to the same object of class C to which refernence variable 'c' in object b is pointing to.
in constructor of All can i write,
this.c = b.c; //??
i don't want any class of above to be the inner class of any other class.
Also one more doubt...
if i don't have a reference variable of type C in class All, can i still invoke methods of class C thro reference variable b contained in class All
like...
in a method of class All can i say..
b.c.CMethod();
\\if i don't have reference variable of type c in class All
what should i do?
please help me. thanks.
[This message has been edited by NIKHIL EROS (edited October 06, 2001).]
[This message has been edited by NIKHIL EROS (edited October 06, 2001).]
23 years ago
i want to know about Typecasting.
When we typecast a class to its Child class, like...
A-->B
A a = new A();
B b = new B();
b = (B) a;
how can we visualize it? i mean to ask how a child class reference can point to a parent class object??
23 years ago
i have used my own TreeModel by extending TreeModel class, its reprsenting the tree nodes well, i have given my own functionality for deletion as its my TreeModel, but when i delete any node its not getting deleted the same moment.
Instead when i collapse and again expand the Parent Node (from which i deleted the Child Node) then it shows that the Child node has been deleted. I have also tried using Validate() and Paint() funtions as well, but of no use.
please help me soon. Thanks in advance
23 years ago