I think the screenshot is worth a couple of paragraphs
The best way I can think of doing it is to check for the length of the string and depending give/take \t, but it just seems inelegant. Is there a simpler/better way?
I would use a JTable for this. You can put one in a JScrollPane. This will get you aligned columns automatically. Plus you will get column headers which will aid in understanding what the data means.
If you want to stick with plain text and have an upper bound on the length of fields (which you'd need to guarantee alignment), then you could use printf.
Related
I'm currently using a jTextArea, and that has a setLineWrap() method to indicate whether text should be wrapped or not. Do jTextPanes have an equivalent to this? I know it can wrap words, but I need it to wrap characters.
For example, "oooooooooooo..." should be wrapped and displayed as two or more lines of o's instead of one long line with a scroll bar. So is this possible with jTextPanes?
JTextPanes word wrap automatically, you have to set the size.
jTextPane.setSize(someValue);
The size should be set to something small.
But this doesn't help you because it doesn't do that with characters... Try using <br> maybe? Or check this link: http://java-sl.com/wrap.html
If I have a lot of values with close values, the data labels overlap. For example this sequence of 14's:
Is there a way to de-clutter this somehow or "hide" labels that contribute to the clutter?
For version 3.x you can try xAxis.setLabelCount(4), but in your case may be better is xAxis.setGranularity(1f)
xAxis.setLabelsToSkip(5) it will skip five label. automatic lab
I want to display multiple-line text for each item in combobox. Words should go to the next line automatically if the exceed the width of combobox. How to achieve this?
String meanings;// array which contains pretty long sentences
JComboBox<String> meaningsComboBox=new JComboBox<String>(meanings);
Maybe wrapping each value into html will help you(this trick work with JLabels), example here.
In another way, I think, you need make custom renderrer, example here
Pretty self-explanatory. Whenever I set the contents of a label, any spaces at the beginning or end are removed. I've looked at the API and found little to help me. setExtraSpaces() will add spacing to the top and bottom, which I don't want. Something like setLeft doesn't seem to add any actual space -- perhaps some other layout is conflicting to cause that not to happen but even then it seems like a bit of a work around. So, basically, I just want to know if there's any way to make the content exactly what I put in?
From the JavaDoc:
setContents
public void setContents(String contents)
The contents of a canvas or label widget. **Any HTML string is acceptable**.
Hey,.. i wanna show pictures with names onit in a jList, i know it get's also in a JPanel but i'm now using a jList, doesn't matter..
My question is why does the jlist don't fit the images only in 2 horizontal 'cells' and then go one row down?
sry my english is bad and i don't know how to describe it better, but look on the picture, why does the jlist dont set the e.g. 3rd picture right next to the 2nd?
JList.HORIZONTAL_WRAP works correctly in the ListDialog JWS demo, as described in Initializing a List. I suspect a layout problem, but you might compare your code to the examples found there.
If you use HORIZONTAL_WRAP you can adjust the number of columns with setVisibleRowCount. If you want them automatically fitted to the width of the list, use 0 or something negative.