What is the best way to display text diagonally and vertically in a JApplet. I want to show the string variable.
Example of a diagonal format can be found here.
Example of a vertical format:
V
E
R
T
I
C
A
L
There are components that do this naturally.
You could try using a JTextArea. Just add a new line after every character for vertical. Then you can add multiple spaces before every line for diagonal. Actually text area support letter wrapping so you could use a monospaced font and create the textarea with a single column and it should do the vertical for you.
You could use a Text Icon for vertical. Then maybe customize the code for diagonal to add a gap for every letter.
Related
When I underlined a custom font it used the default single line underline. However, I want the underline to be the same style as the font which cannot be done. Then I noticed that underscore character can be used as an underline by drawing a string of underscores on top of the text I want underlined.
Now when trying to draw string, I'am having hard time to find the coordinates and I don't want to hardcode coordinates, so I need get the coordinates of the text I want to draw onto.
Apparently the text I'am drawing onto is of JButton and JLabel, and there is no way to get the coordinates of its text.
Any help on getting the coordinates or help on using the style of font on underline would be appreciated.
Edit: By style of the font for the underline, I mean this:
I am trying to use MPAndroidChart to make a Line chart in my app. I want to change the grid color of certain parts of the grid, when a value is selected on my graph.
Something like this:
.
I know you can change the color of a grid line using :
xAxis.setGridColor()
//or
yAxis.setGridColor()
But this changes the color of the entire grid line either for the x-axis or y-axis. I need a way to set the color of only a section of the x-axis grid line, or y-axis grid line.
Please try this if you want to change axisline color, you can use below method.
mChart.getYAxis().setAxisLineColor(getResources().getColor(R.color.some_color));
mChart.getAxis().setAxisLineColor(getResources().getColor(R.color.some_color));
I don't think you can change color a section
Hope this will help!
I'm making a Pascal triangle and I want vertical text align.
I output everything in Text Panel, I tried many options here but none seems to work. There are some align options in this editor but there are too many, I don't know which one will do what I want, can't find anything about that anywhere.
When it gets to double/triple digits it's not aligned vertically anymore. I'm making it from left to right, not in triangle shape.
To vertically align text on adjacent lines, a fixed width Font (such as Courier) can be used. If using Swing, you can can set the Font of a JTextComponent using the appropriate method:
JTextArea textArea = new JTextArea();
textArea.setFont(new Font("Courier", Font.PLAIN, 12));
If rendering with html, you can use the <pre> tag.
The fixed width Font will let the nth character on one line be aligned with the nth character on all other lines.
So I have a JTextArea which shows the text right from the top left corner. I want some margin on all 4 sides, so there's some space between text and boundary of the area.
I have researched a lot and could not find any solution. How can I do it?
Also, I was thinking maybe put up a label on all 4 sides to create dummy margin. How can I create a JLabel with certain width and height?
May be I dont understand your question correctly. However you can use setMargin()
// set the margin for all four sides
tt.setMargin( new Insets(10,10,10,10) ); // tt is JTextArea instance
Some Important Links
1. setMargin API
2. Class Insets
I'm using JTextPane and JButton
If I click the Button, I hope every characters in JTextPane will have a dot under it
Is there any way to do this?
The big problem is how to add dots under every characters :(
You can make use of javax.swing.text.DefaultHighlighter, which handles character spacing of a text component in order to do background painting on that component.
public class DotHighlighter extends DefaultHighlighter {
// implementation
}
Implementing a custom highlighter is a moderate sized amount of work, but here's a nice code example of an underlining highlighter implementation; you should be able to modify it to draw dots.
http://java-sl.com/tip_colored_strikethrough.html you can use the example of colored strikethrough.
All you need is to draw your line under letters. Just set Stroke to your Graphics2D instance. (See BasicStroke and dash pattern)
Are you using a monospaced font? If so, it would be possible to create a new label and display a string that is composed only of periods (of the same length as the string in the original label), and display that label a bit lower than the first.
I.E., if your label says 2446, then you could make a second label that's 5 or 10 pixels lower, which says .....
Again, this will only work with a monospaced font- for any other fonts, it would still be possible, but it would involve a more complicated solution (looping through each character, finding its location, and then managing to display a dot beneath it), I believe.