• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jtable dialog box  RSS feed

 
Matt Jacks
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to pop up a dialog from one of the tables on my screen. I am having issues. I am not sure if I set up the editor properly. I have seen code where dialogs are created outside of the custom editor's code and inside, which is proper? I know i have to use a button and encapsulate the button with the editor, should i show the dialog when the button is pushed, or when the editor begins editing? Where can I find examples/information
 
keiyia jackson
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is what i was given for a similar questions
............

table = new JTable( rr, clm );
//Registrating for cell selection.
table.setCellSelectionEnabled(true);
ListSelectionModel cellSelectionModel=table.getSelectionModel();
//assign the selection mode
cellSelectionModel.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
//add the listener to the table selection model
cellSelectionModel.addListSelectionListener(this);
........
// 4. add the table to the container
JScrollPane scroller = new JScrollPane(table );
getContentPane().add(scroller, "North" );
JPanel jpnl1 = new JPanel();
back = new JButton("Back to Do a New Search");
back.addActionListener(this);
jpnl1.add(Box.createRigidArea(new Dimension(5,5)));
jpnl1.add(back);
getContentPane().add(jpnl1, "South");

JPanel jpnl2 = new JPanel();
JLabel displayheadline = new JLabel("Click a airline that you
prefer to make a booking");
displayheadline.setForeground(Color.black);
displayheadline.setFont (new Font("SansSerif",Font.BOLD,14));
jpnl2.add(displayheadline);
getContentPane().add(jpnl2, "Center");
repaint();
}
//7. List selection listener method to be implemented
public void valueChanged(ListSelectionEvent e) {
int rows;
String selectedData = null;
int[] selectedRow = table.getSelectedRows();
JFrame f3=null;
Vector row_selected = new Vector();
Vector row = new Vector();
for (int j=0; j<clm.size();j++) {>
selectedData = (String)
table.getValueAt(selectedRow[0],j);
row.addElement(selectedData);
}
row_selected.addElement(row);
this.setVisible(false);
f3 = new
BookSeats(hostName,portNum,dbName,row_selected,clm); //opened a new window
f3.show();
}
public void actionPerformed(ActionEvent evt)
{ JButton arg = (JButton)evt.getSource();
if (arg.equals(back))
{ if(Start.operMode.equals("Local")) {
this.setVisible(false);
SearchInput f = new SearchInput(dbName);
f.show(); }
else if (Start.operMode.equals("Network"))
{
this.setVisible(false);
SearchInput f = new SearchInput(hostName,portNum);
f.show(); }
}
else
{ //for future button; handling code will go here
}

}
/**
* Notifies this component that it has been added to a container
* This method should be called by <code>Container.add</code>, and
* not by user code directly.
* Overridden here to adjust the size of the frame if needed.
* @see java.awt.Container#removeNotify
*/
public void addNotify()
{
// Record the size of the window prior to calling parents addNotify.
Dimension size = getSize();
super.addNotify();
if (frameSizeAdjusted)
return;
frameSizeAdjusted = true;
// Adjust size of frame according to the insets and menu bar
javax.swing.JMenuBar menuBar = getRootPane().getJMenuBar();
int menuBarHeight = 0;
if (menuBar != null)
menuBarHeight = menuBar.getPreferredSize().height;
Insets insets = getInsets();
setSize(insets.left + insets.right + size.width, insets.top +
insets.bottom + size.height + menuBarHeight);
}
void exitApplication()
{
try {
// Beep
Toolkit.getDefaultToolkit().beep();
// Show a confirmation dialog
int reply = JOptionPane.showConfirmDialog(this,
"Do you really want to
exit?",
"JFC Application - Exit" ,
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
// If the confirmation was affirmative, handle exiting.
if (reply == JOptionPane.YES_OPTION)
{
this.setVisible(false); // hide the Frame
this.dispose(); // free the system resources
System.exit(0); // close the application
}
} catch (Exception e) { }
}
/**
* This is an Inner class for Window clossing. It gets WindowEvent and
* eventually calls the exitApplication method of the out class.
*
*/
class SymWindow extends java.awt.event.WindowAdapter
{
public void windowClosing(java.awt.event.WindowEvent event)
{
Object object = event.getSource();
if (object == DisplayTable.this)
Start_windowClosing(event);
}
}
void Start_windowClosing(java.awt.event.WindowEvent event)
{
Start_windowClosing_Interaction1(event);
}
void Start_windowClosing_Interaction1(java.awt.event.WindowEvent event) {
try {
this.exitApplication();
} catch (Exception e) {
}
}

// Used by addNotify
boolean frameSizeAdjusted = false;
Vector rr = new Vector();
Vector clm = new Vector();
JTable table;
JButton back=null;
JButton exit=null;
String hostName="";
String dbName;
String portNum;
}
 
Paul Stevens
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this site.SwingExamples
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!