简体   繁体   中英

show jtable in text area

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM