• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a dialog box contain JTable ?

 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
i want a table like structure to display in dialog box
i tried this
JOptionPane.showConfirmDialog(frame,table);
where frame is JFrame and table is object of type JTable
but it's giving me runtime error..
actullay i just want a table to appear with heading and
only one row...
is it possible???
BHupendra Mahajan
 
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You'll have to create your dialog window by creating a JDialog window and adding the JTable (and any other widgets you want) to it yourself. JOptionPane is just used for building simple dialogs quickly to show error/confirmation messages and that sort of thing, and it probably doesn't know how to handle tables.

-Nate
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Nate
i tried the option by u....
but it's still giving me error..
my code is...

Bhupendra Mahajan
 
Nathan Pruett
Bartender
Posts: 4121
IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bhupendra,

It is not a problem with the table per se... it is a problem with the data you are sending it. The row Vector needs to be a Vector of Vectors, not just a Vector of Strings. (There has to be a way to show what row the data belongs to!) Replace your dialog with the one below and it will work!


-Nate
 
Mahajan Bhupendra
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Nate..
actullay i solved the problem..
it was the same as u said..
but i forgot to reply back here..
anyway thanks..

------------------
Bhupendra Mahajan
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Bhupendra/Nathan

Thanks for the wonderful example. After displaying table in the Dialog Box, i want to click individual cells and store that value in a text box. Is it possible and how i can achieve it?
Waiting for a positive reply.
 
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch.

The recommended way to achieve this is a add a selection listener to the table's selection model. Once you get a selection notification, you can figure out the selected cell and process the value.
Recommended reading: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#selection
 
Sachendra Pal
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Maneesh Godbole wrote:Welcome to the Ranch.

The recommended way to achieve this is a add a selection listener to the table's selection model. Once you get a selection notification, you can figure out the selected cell and process the value.
Recommended reading: https://docs.oracle.com/javase/tutorial/uiswing/components/table.html#selection



Can you please help me out with a code example?
 
Maneesh Godbole
Bartender
Posts: 11497
19
Android Google Web Toolkit Mac Eclipse IDE Ubuntu Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The link I posted already contains code with explanation. Did you go through it?
We do not just hand out code here at the Ranch. Show us your code, tell us where you are stuck and we will help point you in the right direction
 
reply
    Bookmark Topic Watch Topic
  • New Topic