+20

How to know the number of characters we can place in a line ?

Suppose u make some pattern & it looks fine in your device (because width of pattern is less than width of device) But in other device, it might not get fitted (because it have little less characters capacity per line) So if there will be someway to identify the no. of characters we can put in a line for different devices, then it will easy to give instruction for maintaining pattern. //ie, we can find maximum width we can have for pattern for a device. Some function available for that ?

1/11/2019 12:33:16 PM

Gaurav Agrawal

16 Answers

New Answer

+12

You maybe finding the solution for java. I have a trick for it - not implemented though. Get the device width java.awt.toolkit.getDefaultToolkit().getScreenSize().getWidth() Measure the approximate length for a character - you may use a ruler 📏😁 Divide the width by approx. length of char and maximum length of a char sequence can be obtained. But this cannot be done practically in SL as it doesn't support java.awt, as we all know

+11

⏩ Prometheus ⏪ We can do error & trial for a particular device , but cannot do for all device. //the idea of this I get from Ace sir answer here (see 1st point) https://www.sololearn.com/Discuss/1652441/?ref=app

+7

As far as I know, I don't think anything except for web supports that. And it seems the only method now is trial and error, unless you know both the screen size and the size of characters

+7

You can get the width of console window with Python and adjust your code for it. Don't be too optimistic thinking you could do this HERE as well: You'll get the values from the compiler PC. ;-)

+7

Hy mohammad elahi welcome to Sololearn q/a Please stop spamming with unrelated answers in q/a section //U can delete your unrealted answers from q/a posts.

+7

Ace sir, if possible in java or kotlin //on SL, even if not possible on SL, then also I would like to know.

+5

Gaurav Agrawal Is this for a specific language? Because some have support (libraries) to assist you in a task like this.

+4

Emoji FanBoy, huh?

+4

Gaurav Agrawal I think the Apache libraries had some word wrapping libraries but those have been depreciated for some time now. Your best bet is to look for a word-wrapping library so you won't have to do all the work from scratch.

+4

Seniru Pasan is there a way of doing it with JavaFX?

+4

Seniru Pasan JavaFX is a different GUI toolkit.

+3

What does the Python say? is javafx a different thing?

+3

What does the Python say? so it support other packages right?

+3

Seniru Pasan yes so I suppose I could use your way. Thanks

+2

HonFu Not PC though😀 Gaurav Agrawal Once I had read some article exactly how to do this in various language. Now problem is neither I know Java was amongst them or not nor I remember where is the article.

+1

What does the Python say? wc