0

im working on a project and have a need to display JTable built from resultset in another form's text area. I can display it in option dialog same way as in this example: Most simple code to populate JTable from ResultSet (example with 20 votes) but i need it to be in my form. Question is, is there even a way to do it using text area or i should use other item, such as label/panel etc

Thank you
Community
  • 1
  • 1
user3502301
  • 9
  • 1
  • 5
  • `or i should use other item, such as label/panel etc` - use a JTable. You already know it works. Don't reinvent the wheel. – camickr Apr 21 '14 at 16:05

1 Answers1

0

To answer your direct question: No you can't display a JTable inside of a JTextArea, not without completely perverting the JTextArea and its functionality.

I'm not sure why you'd even want to do such of a thing, since a JTextArea displays text, and you can't display a component inside of it, not without completely messing up its functionality. That is, unless I'm misinterpreting your question, and if so, please clarify it.

What exactly are you trying to display in the JTextArea? The JTable's data? If so, that's a completely different thing. If that's the case, then sure, this can be done:

  • Set the JTextArea's font to be mono-spaced
  • Use String formatting via String.format(...) to allow you to display columns of data in a tabular fashion.
  • As with any solution the details of the solution will depend on the details of the problem.
Hovercraft Full Of Eels
  • 283,665
  • 25
  • 256
  • 373
  • well really i just dont know how to import it there. I had a gui built for my reports having a text area, was thinking i could import jtable there as well. if not i can change it to what ever i have to, i just dont know what would be the best way – user3502301 Apr 21 '14 at 15:24
  • @user3502301: please clarify your question and your comments a little bit as I'm having a great deal of difficulty parsing exactly what you're trying to say here. What does "import" have to do with anything as you can import any core class you'd like? Please explain the ***details*** of your problem. Don't assume that we know what you're talking about or trying to do please. – Hovercraft Full Of Eels Apr 21 '14 at 15:25
  • ok, the best word would be - Display. I have a JTable created from resultset. I need it to be displayed in my form. Question - how? i know how to show it in jDialog. but that is not what i need. – user3502301 Apr 21 '14 at 15:26
  • @user3502301: The best way to display a JTable with data would be to do just that: display that JTable in your GUI. Add it to a JScrollPane and add that JScrollPane into your GUI -- you never tell us why you can't do this! But again, I think that we're just talking past each other here. – Hovercraft Full Of Eels Apr 21 '14 at 15:28
  • hehe, yeah. i cant figure out how to display that JTable in my GUI. I was able to display a resultset using string. But this way all information is hard to read, thats why i was looking for the way to use jtable – user3502301 Apr 21 '14 at 15:29
  • @user3502301: then this is a completely different question. You need to learn the basics of adding components to containers, and to be perfectly frank you need to learn how to ask straight forward clear questions. To help you with this, we need to know the set up of your GUI the layout managers etc. If you're using a GUI builder, then stop doing this until you understand the GUI library just a little. Use the Swing tutorials which you can find [here](http://stackoverflow.com/tags/swing/info), and do some studying. – Hovercraft Full Of Eels Apr 21 '14 at 15:31
  • @user3502301: maybe the confusion was in your use of the term "text area". I assumed that you meant showing a JTable inside of a `JTextArea` which to be quite frank makes absolutely no sense. Perhaps you mean that you wish to display the JTable within a GUI. If so, concentrate on the [Layout out Components Within a Container Tutorial](http://docs.oracle.com/javase/tutorial/uiswing/layout/). Note that programming is an exercise in precision, and therefor so is asking programming-related questions. – Hovercraft Full Of Eels Apr 21 '14 at 15:36
  • yes you are right, thanks a lot, i'll dig into this. – user3502301 Apr 21 '14 at 15:44