Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6342117
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T20:10:36+00:00 2026-05-24T20:10:36+00:00

In order to be able to display a sentence on a, say, JPanel with

  • 0

In order to be able to display a sentence on a, say, JPanel with a GridLayout(1,0) [i.e., only one line/row] and then be able to draw a syntax tree (or similar) above it, I want to display the sentence as a row of Strings, which each include one word.

The single Strings should then be either selectable (as in a JList), or I should at least be able to get their Location on the JPanel via getLocation().

Up to this point I have tried the following options, and had the following issues:
– Single Strings as JLabels: The JLabels are stretched out to fill the JPanel width, re-sizing them to fit the single String they’re displaying seems complicated. I would want to be able to do this, however, to make the sentence look like a sentence and not like a badly layed out table.
– JList: All the functionality I want, but I’m unaware of an option to re-size the “cells” of a single String (cf. JLabel above). Also, I’m having difficulties restricting display of the JList to a single line/row (cf. another of my questions).
– JTextArea: I couldn’t get my head round how to get the Location of the single Strings that I had appended to the JTextArea.

I’m aware that drawString() might be an option, but I’m afraid to use it since I don’t want to mix AWT and Swing. Also, I would need to calculate the int values for x and y for every single String. And I’m not sure whether I’d be able to get their Locations at all (although I could of course save their ints in a Map or Vector since I have to calculate them anyway).

Thankful for any suggestions! Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T20:10:36+00:00Added an answer on May 24, 2026 at 8:10 pm

    I would use JTextArea and method modelToView()/viewToModel() to get x,y for position in nthe string and position in the string for coordinates x and y.

    Also use Utilities class getWordStart() getWordEnd() getRowStart() getRowEnd() methods.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In order to be able to reuse segments of code through multiple application, I
In order to be able to use this awesome plugin: Jquery iphone contacts i
I am trying to understand how stringstream works in order to be able to
I added php_value session.cookie_domain .example.com to my .htaccess in order to be able to
We are creating typical web applications secured by https. In order to be able
Possible Duplicate: How to invalidate the file system cache? In order to be able
I am using Able Commerce and need to customize the Customer Order Notification email
So I've resigned myself to not being able to use the order of a
For clarification, are you able to use MySQL this way to sort? ORDER BY
In one of my app's user interfaces i want my app display a scrolling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.