Ruel Soriano

Greenhorn
+ Follow
since May 17, 2007
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 Ruel Soriano

can someone give sample that has a checkbox in every node. I made JTree format of data from database, problem is i can't make a checkbox for my JTree, and I explore how to make one its get me more confused. so if someone can show how to make i would appreciate it.
15 years ago
if i can get some code or extract a code just to be my guide......i know how to get the column name from and extract it to jtree but my problem is how if one of my column has a child, automatically it add on the last column name i created.
for example col_1, col_2, col_3 will be the node for root, what if i have a child for for each of the column, all of them will be in the last column like col_3.......

so please give a solution for this.....urgent.
15 years ago
Thanks for the code, it really helped me, your a saver.....
till next time.
Thanks again.
15 years ago
sorry for that, but i could not start what i'm doing coz i dont have any idea and can't of one, well i know how to use ResultSetMetaData and displaying the column but my big problem is how can i make a child of each...for example

Table [table_1] with column [column_1 column_2 column_3]
Table [table_2] with column [col1 col2 col3]

how can i make them to display in JTree like:

table_1
|
|-----------column_1
|-----------column_2
|-----------column_3
table_2
|
|------------col1
|------------col2
|------------col3

could someone give me an idea or better a sample code for this....
thanks in advance.....
15 years ago
greetings, could someone send me simple code on how to get the column names from table and display it in JTree format. I have two table maintenace and report, the node name would be the two table name and its child would be its corresponding column name and child for column would be its value or element....please someone help me for this...
thank you very much.
15 years ago
thanks for the reply, but could you please give me a brief example of that code, i really don't know how to do that.
15 years ago
could someone give me sample code of tree with checkboxes. And how could handle an event to save all the selected checkboxes in a database.......
can someone please send sample....i appreciated it very much.
thanks..
15 years ago
Thanks for the reply.....but I have something to add, I want my selected value from the table will be display to another class. For example, class Table and Class Main....when i click button Find in the Main class the table from Table Class will be display and when I select value from the table and click the button Select the selected value will display to the Textfield of Main Class. How can i get it.
Many thanks and I hope you could help me again.......
15 years ago
can someone look and check my codes and tell me why it didn't work when i choose Minimize, Maximize, Resize and change Title in Menu.....nothing happened if i chose from [Minimize, Maximize, Resize and change Title]any of them, is there something wrong with my actionPerformed...
here are the codes.....

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;

public class Application {
/**
* Creates an instance of JFrame with certain attribute passed
* as argument.
*
* @param titleWindow title
* @param dimensionDimension of window
* @return instance of JFrame
*/
protected JFrame createMainFrame(String title, Dimension dimension) {

// create an instance of the window
JFrame frm = new JFrame(title);

// set the size of the window
frm.setSize(dimension);

// move the window to coordinate X:200, and Y:300
frm.setLocation(new Point(200,300));

return frm;
}
/**
* This section creates a menu bar instance that can be added in an
instance of
* JFrame.
*
* @return
*/
protected JMenuBar createMainMenu() {
// create the main menu bar
JMenuBar menuBar = new JMenuBar();

// create a menu holder
JMenu fileMenu = new JMenu("File");

// this change the font of the menu item
fileMenu.setFont(new Font("Tahoma", Font.PLAIN, 12));

// add the menu holder to the main menu
menuBar.add(fileMenu);

// to create a menu item that will hava an action use JMenuItem
JMenuItem newMenu = new JMenuItem("New...");
newMenu.setFont(new Font("Tahoma", Font.PLAIN, 12));
// add item to filemenu
fileMenu.add(newMenu);

/*
* Adding sub menus, to add sub menus you add an instance of JMenu
* within JMenu
*/
JMenu recentFiles = new JMenu("Recent Files");
// you dont need tochagne the font every time, i just want to use tahoma
recentFiles.setFont(new Font("Tahoma", Font.PLAIN, 12));
//add to file menu
fileMenu.add(recentFiles);

// then add JMenuItem in the newly create JMenu
JMenuItem item1 = new JMenuItem("File 1");
recentFiles.add(item1);
JMenuItem item2 = new JMenuItem("File 2");
recentFiles.add(item2);
JMenuItem item3 = new JMenuItem("File 3");
recentFiles.add(item3);


//adding a separator
fileMenu.addSeparator();

// adding exit menu item under file menu after the separator
JMenuItem exitMenu = new JMenuItem("Exit");
exitMenu.setFont(new Font("Tahoma", Font.PLAIN, 12));
// add item to filemenu
fileMenu.add(exitMenu);

/*
* associating an action to a menu; there are different ways to do
this but this is
* the simplest form; use the method addActionlistener()
* 1: create an instance of ActionListener; however ActionListener is
an interface,
* the only way you can create an instance is to implement it, this
is an inline
* implementation
*/
ActionListener exitAction = new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
// this will be called if the menu is clicked
// exit the application
System.exit(0);
}
};

/*
* 2: associate to a menu item (the exit menu item)
*/
exitMenu.addActionListener(exitAction);

// to add another menu with the same level of File menu, you need to add another
// JMenu in the instance of JMenuBar

JMenu windowMenu = new JMenu("Window");
menuBar.add(windowMenu);

//adding subMenu for windowMenu
JMenuItem minimizeMenu = new JMenuItem("Minimize");
windowMenu.add(minimizeMenu);
ActionListener minimizeAction = new ActionListener(){
public void actionPerformed(ActionEvent args){
JFrame frame = new JFrame();
frame.setExtendedState(JFrame.ICONIFIED|frame.getExtendedState());
}
};
minimizeMenu.addActionListener(minimizeAction);

JMenuItem maximizeMenu = new JMenuItem("Maximize");
windowMenu.add(maximizeMenu);
ActionListener maximizeAction = new ActionListener(){
public void actionPerformed(ActionEvent args){
JFrame frame = new JFrame();
frame.setExtendedState(JFrame.MAXIMIZED_BOTH);

}
};
maximizeMenu.addActionListener(maximizeAction);

JMenuItem resizeMenu = new JMenuItem("Resize to 500,500");
windowMenu.add(resizeMenu);
ActionListener resizeAction = new ActionListener(){
public void actionPerformed(ActionEvent args){
new Application().createMainFrame("Example Application",new Dimension(500,400));
}
};
resizeMenu.addActionListener(resizeAction);

JMenuItem changetitleMenu = new JMenuItem("title to Welcome");
windowMenu.add(changetitleMenu);
ActionListener changetitleAction = new ActionListener(){
public void actionPerformed(ActionEvent args){
new Application().createMainFrame("Welcome", new Dimension(500,400));
}
};
changetitleMenu.addActionListener(changetitleAction);
// each JMenuBar, JMenu, JMenuItem are treated as individual instance or objects
// they are registed to each other on how you issue the add command call


return menuBar;
}

/**
* Use to create and start the frame
*
*/
public void start() {
// create main window
JFrame frame = createMainFrame("Example Application", new Dimension(500,400));

// add main menu, and create children
frame.setJMenuBar(createMainMenu());

// show the frame, if this is not called, the application will be terminated.
// and now window will be displayed.
frame.setVisible(true);
}


/**
* Main executable point, entry point of execution.
* @param args
*/
public static void main(String[] args) {
new Application().start();
}

}
15 years ago
in this part i got errors, it says invalid cursor state.....
and these are the codes were i got it....

data.addElement(new Vector());
((Vector)data.lastElement()).addElement(rs.getString(1));
((Vector)data.lastElement()).addElement(rs.getString(2));
can someone get me a new code to run this program...
I would appreciate it very much......
greetings,
how can i get value from JTable and set it to textfield. I have to classes, one for JTable class and other for Textfield class, how can i get the value when i select value from JTable class and put it on textfield which is another class.....
i really need this, please help me.....
thanks..
15 years ago
check this code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*;
import java.sql.*;
import java.util.*;
import javax.swing.JScrollPane;
import javax.swing.border.*;


public class TestingAgain extends JFrame{
Connection con;
Vector columnName, data;
JTable myTable;
JScrollPane myPane;
JButton select;

/** Creates a new instance of TestingAgain */
public TestingAgain() {
JPanel panel = new JPanel();
select = new JButton("select");

try{
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch (ClassNotFoundException cnfEx)
{
cnfEx.printStackTrace();
}
con = DriverManager.getConnection("jdbc:odbc:MS Access Database", "", "");
Statement stat = con.createStatement();
ResultSet rs = stat.executeQuery("select group,description from groupcode");

columnName = new Vector();
columnName.addElement("Group");
columnName.addElement("Description");

data = new Vector();
while(rs.next());
{
data.addElement(new Vector());
((Vector)data.lastElement()).addElement(rs.getString(1));
((Vector)data.lastElement()).addElement(rs.getString(2));
}
rs.close();
stat.close();
con.close();
}
catch (SQLException sqlEx)
{
sqlEx.printStackTrace();
JOptionPane.showMessageDialog(null,"Error loading table.\nPlease check setup");
}
myTable = new JTable(data, columnName);
myPane = new JScrollPane(myTable);
Border etchedBorder = BorderFactory.createEtchedBorder();
Border titleBorder = BorderFactory.createTitledBorder(etchedBorder,"Group Code");
myPane.setBorder(titleBorder);
panel.add(myPane);
panel.add(select);

panel.setLayout(new BoxLayout(panel,BoxLayout.Y_AXIS));
getContentPane().add(panel);
pack();
setVisible(true);
}
public static void main(String[]agrs)
{
new TestingAgain();
}
}

i have a problem getting the data in my JTable it display the JOPtion...i think i have error in the part:
data.addElement(new Vector());
((Vector)data.lastElement()).addElement(rs.getString(1));
((Vector)data.lastElement()).addElement(rs.getString(2));
can someone get me a new code to run this program...
I would appreciate it very much......