Rakesh Gudur

Ranch Hand
+ Follow
since Apr 29, 2002
Merit badge: grant badges
For More
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 Rakesh Gudur

Hi,
My requirement is to freeze the first column of a JTreeTable. With a JTable the job is a bit easier and I've seen some examples.
But how do I freeze the first column in a JTreeTable. My requirement is the first column is a JTree and the rest are the table rows and columns. The scrollbar should appear only for the columns greater than 0. There should be a vertical scrollbar which scrolls the JTree and the JTable.
I tried using two different JTreeTables and then add the column of the second treetable to the first. But when I expand and collapse the parent nodes the table rows are not expanding and collapsing.
Pls give me a solution for this. If you can give me some code snippets that would be great. Thanks in advance.
My code is like this, but it doesn't work as I expect:
import javax.swing.*;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.event.ChangeListener;
import javax.swing.event.ChangeEvent;
import javax.swing.table.*;
import java.awt.*;
import java.awt.event.*;
public class Tester extends JPanel{
final static boolean standaloneMode=true;

JMenuBar mb = new JMenuBar();
JMenu file = new JMenu("File");
JMenu reports = new JMenu("Reports");
JMenuItem filePrint = new JMenuItem("Print");
JSeparator separator = new JSeparator();
JMenuItem fileQuit = new JMenuItem("Quit");
JMenuItem itemList = new JMenuItem("List All Items");
JMenuItem browseItems = new JMenuItem("Browse Items");
JFrame frame=new JFrame();
JViewport innerPort, headers;
JScrollBar scrollBar;
JScrollPane scrollPane;
JTreeTable fixedTable;
JTreeTable scrollTable;
TableModel tm;
TableColumnModel fixedColumnModel, scrollColumnModel;
int rowHeight=64;
JTree tree;
DefaultMutableTreeNode[] nodes;
JTextField findField;
JPanel homePanel=null;
JPanel browsePanel=null;
JPanel scrollPanel=null;

public Tester (){
homePanel = new JPanel();
homePanel.setLayout(new CardLayout());
scrollPanel = new JPanel();
scrollPanel.setLayout(new BorderLayout());
this.add(scrollPanel);
scrollTable=new JTreeTable();
// adjustColumnWidth(scrollTable.getColumn("End Date"), 150);
scrollTable.setRowHeight(rowHeight);
fixedTable = new JTreeTable();
fixedTable.setTreeTableModelAdapter(scrollTable.getTreeTableModel(), fixedTable.getTree());
freezeColumn();
fixedTable.setRowHeight(scrollTable.getRowHeight());
headers = new JViewport();
headers.add(scrollTable.getTableHeader());
JPanel topPanel = new JPanel();
topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
adjustColumnWidth(fixedColumnModel.getColumn(0), 100);
JTableHeader fixedHeader=fixedTable.getTableHeader();
fixedHeader.setAlignmentY(Component.TOP_ALIGNMENT);
topPanel.add(fixedHeader);
topPanel.add(Box.createRigidArea(new Dimension(2, 0)));
topPanel.setPreferredSize(new Dimension(400, 40));
JPanel headerPanel = new JPanel();
headerPanel.setAlignmentY(Component.TOP_ALIGNMENT);
headerPanel.setLayout(new BorderLayout());
JScrollPane scrollpane = new JScrollPane();
scrollBar = scrollpane.getHorizontalScrollBar();
headerPanel.add(headers, "North");
headerPanel.add(scrollBar, "South");
topPanel.add(headerPanel);
innerPort = new JViewport();
innerPort.setView(scrollTable);
scrollpane.setViewport(innerPort);
scrollBar.getModel().addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e)
{
Point q = headers.getViewPosition();
Point p = innerPort.getViewPosition();
int val = scrollBar.getModel().getValue();
p.x = val;
q.x = val;
headers.setViewPosition(p);
headers.repaint(headers.getViewRect());
innerPort.setViewPosition(p);
innerPort.repaint(innerPort.getViewRect());
}
});

JPanel bottomPanel = new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.X_AXIS));
fixedTable.setAlignmentY(Component.TOP_ALIGNMENT);
bottomPanel.add(fixedTable);
bottomPanel.add(Box.createRigidArea(new Dimension(2, 0)));
innerPort.setAlignmentY(Component.TOP_ALIGNMENT);
bottomPanel.add(innerPort);
bottomPanel.add(Box.createRigidArea(new Dimension(2, 0)));
scrollPane= new JScrollPane(bottomPanel,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
JViewport outerPort = new JViewport();
outerPort.add(bottomPanel);
scrollPane.setColumnHeaderView(topPanel);
scrollPane.setViewport(outerPort);
scrollTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
scrollPanel.add(scrollPane);
scrollTable.validate();

}
public void freezeColumn(){
scrollColumnModel = scrollTable.getColumnModel();
fixedColumnModel = new DefaultTableColumnModel();
TableColumn col = scrollColumnModel.getColumn(0);
scrollColumnModel.removeColumn(col);
fixedColumnModel.addColumn(col);
fixedTable.setColumnModel(fixedColumnModel);
}
void adjustColumnWidth(TableColumn c, int size) {
c.setPreferredWidth(size);
c.setMaxWidth(size);
c.setMinWidth(size);
}
public static void main(String [] args){
try {
final String windows =
"com.sun.java.swing.plaf.windows.WindowsLookAndFeel";
UIManager.setLookAndFeel(windows);
JFrame _frame = new JFrame();
_frame.getContentPane().setLayout(new BorderLayout());
_frame.getContentPane().add(new Tester(), BorderLayout.CENTER);
//((AbstractTableModel)treeTable.getModel()).fireTableStructureChanged();
_frame.setSize(Toolkit.getDefaultToolkit().getScreenSize());
_frame.pack();
_frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});
_frame.show();
} catch (Exception x) {
x.printStackTrace();
}
}
}

thanks in adv. I appreciate an urgent response.......
Rakesh.
[ March 23, 2004: Message edited by: Rakesh Gudur ]
19 years ago
Congrats Scott! That's a good score.
Good luck,
Rakesh.
------------------------
IBM Certified XML Dev.

It is the attitude and aptitude that determines ones altitude.

Congrats Himal! I think you did a lot of har work for the exam..i saw your postings seeking clarifications many times. I think that helped you preparing for the exam.
Good luck for next venture!
Rakesh.
-----------------------
IBM Certified XML Dev.

It is the attitude and aptitude that determines ones altitude.

Alfonso,
There are mechanisms to define uniqueness of data using Schema and XSL elements, but I don't think there is anything to generate a random number.
This might have been left for the applications to handle.
Rakesh.
IBM Certified XML Dev.

Mysticism is a non physical connectivity with the superior cosmic intelligence.

Hai,
So that's the problem with the schema validatior and not the specs!
Rakesh.
IBM Certified XML Dev.

Mysticism is a non physical connectivity with the superior cosmic intelligence

Congrats Samba!
Rakesh.
IBM Certified Dev. in XML and Related Technologies
Jayadev,
Unfortunately there are some mistakes in the answers. In both the cases, I think your answers should be correct.
Please go with what you think is right if you have enough reasoning and proof. Many a times I too came across some such mistakes.
Good luck,
Rakesh.
IBM Certified Developer -XML and related technologies

It is pardonable to aim high and miss, but it is unpardonable to aim low - A Gujarathi Industrialist

Hi Jayadev,
As Vasudha has pointed out, internet transactions are generally B2B and B2C (C2C is also one rare phenomenon).
Whenever it is B2B (Business to Business), the data processing is performed mostly by the systems with no or very less of human intervension.
For eg: in a company A which assembles computers, it raises a Purchase Order when it's stock of monitors comes down a threshold point. The vendor (supplier) receives the request and starts manufacturing the pasrts for A, does the QA, packages it and delivers it. All this happens as a sequence when the stock level goes down.
Here all operations are performed by your computer n/w and manufacturing system. This is a pure B2B scenario.
In case of B2C (Business to Customer), the other end could be a human being who raises a request. The customer could be a single unique entity too who triggers an action.
I hope this helps.
Good luck,
Rakesh.
-----------------------
IBM Certified Developer -XML and related technologies
Congrats Vasudha on making it!
Reg,
Rakesh.
--------------------
IBM Certified Developer -XML and related technologies

Winners don't do different things; They do things differently - Shiv Khera

Hai,
Definitely, if you have some working experience in web based applications (need not be in XML), it will be an advantage for Architecture based questions.
Most of the books give a brief intro abt the architectures of XML based applications. They also deal with this topic in the last few chapters.
You may refer to chapters - E-Buisiness integration, B2B with Microsoft BizTalk Server
in Prof XML 2 ed. of Wrox. I donno if any of the webservices books can help you out, but it's worth checking out.
Also refer to www.java.sun.com or www.msdn.microsoft.com or ibm developerworks for various case studies.
Hope this helps.
Good luck,
Rakesh.
----------------------
IBM Certified XML Dev.
Congrats Samir!
Regards,
Rakesh.
-----------------
IBM Certified XML Dev.
Balaji,
I know the quote is by Gandhi. I read it somewhere. Though I don't have any evidence to prove it in the court of law ;-)
Cheers,
Rakesh.
-----------------
IBM Certified XML Dev.

Be you ever so high, the law is above you.

Vasudha,
I think you are referring to www.skillometer.com
It's a site where you can take the XML exam free.
Good luck,
Rakesh.
-----------------------
IBM Certified XML Dev.

Nothing is good or bad, but thinking makes it so.

Hima,
I think if you can get the latest MSXML parser, it would work fine. It would be available on microsoft site. Best is to install IE 6.0 which has the latest parser.
Good luck,
Rakesh.
--------------------
IBM Certified XML Dev.

Man is a product of his own thoughts. What he thinks he becomes - M.K.Gandhi

Guys,
there seems a lot of hard talk going on.
Please refer to w3c Schema primer at
http://www.w3.org/TR/xmlschema-0/#UnqualLocals
I think this will clear the confusions.
Reg,
Rakesh.
--------------------
IBM Certified XML Dev.