I have a JTextArea where lines are highlighted upon right-click. While I could achieve this (using some great help from my previous post), however I would also want some kind of a toggle functionality i.e. if a line is not highlighted, right-click would highlight it and vice-versa.
With reference to this, is it possible to check whether the selected line is already highlighted or not? Comments/Suggestions?
I understand one way of doing this is to keep a track of all the highlights (maybe using a HashMap as shown in the example here) but this would slightly add to the complexity because I'm writing this method in a helper class that serves to multiple tabs containing these text areas. Any other alternative solution would be very helpful (as in toggling the highlights)
I think you have your answer right there in the link you provided.
Just write your own class extending the JTextArea where each instance will be responsible for storing its highlights then use your own class instead.
BTW #nIcE cOw great answer (+1 there).
SWT has a StyledText class.
You could write a styled text class for Swing, implementing the Document interface, that keeps track of the highlights and whatever other text decorations you want to keep track of. This class would encapsulate the methods that determine the decorations at a given character position in the styled text.
Related
I'm trying to create a mat-accordion that has mat-expansion panels in for loop. The problem is, I need to do some customization like adding a checkbox in front of each expansion and the expansion icon should be placed after some specific text(in this case its book title). The alignments are a mess and as per my understanding, the expansion panels icon can be placed either at the end or beginning. As I think mat-expansion is the correct component to achieve the same. Need some guidance on how to achieve with mat-expansion or should I consider another approach?
Don't try re-styling the mat-accordion for such a huge changes - it was designed to strictly follow material guidelines. Instead, create your own component based on cdk-accordion - basically it's a mat-accordion without any styles, so it gives you much more flexibility.
You can read the official docs (including examples of implementation) here.
I want to post an old book on my wordpress website but since the book is so old there are a lot of words that readers may find unfamiliar. So I was thinking of adding a mouseover with the definition when they hover over a certain unfamiliar word. The problem is that the text is huge and a certain word "x" appears many times in different places in the text. Is is possible to somehow write a single program which creates a mouseover to every single "x" in the text? Or do I need to do each of them separately?
You could write some JavaScript that evaluates the text on pageload and wraps each desired word with a specific CSS class. On this CSS class you could define your mouse hover and the function to be executed.
I want to have a radio button input but instead of mere circles I would prefer another html element (including structure) to illustrate the choices. I thought this might work with the appearance style, but it does not work (probably because the input[radio] might not contain other elements.
Is there any way of styling an input radio, so it displays another HTMLElement instead of its circle?
Why not just leave them radio buttons but make the entire image clickable with label tags?
You might want to look at Uniform. Its a nice and easy way to have complete design control over form elements. Indeed it does require JavaScript but if its not enabled by default Uniform degrades gracefully offering the standard form functionality.
Some browsers allow you to override the settings, but you are going to have to do some super CSS tricks to get it to work.
http://acidmartin.wordpress.com/2009/07/17/using-css-to-style-radiobuttons-and-checkboxes-for-safari-and-chrome/
is a good site that describes how to do what you are talking about. They use a sprite sheet and the browser specific -appearance style to change the look of the box dependent on state.
I wish to provide simple highlighting feature where a user selects some range of text in a TextField and selects a color and that text's background is highlighted with that color like a marker, its a standard feature on most text editors and word processors. How to achieve this in AS3 (not flex) esp without using html/css in TextField.
Here is a good example of what you want to do: http://blog.formatlos.de/2009/06/22/as3-texthighlighter/
Solution here:
http://tom-lee.blogspot.in/2007/01/textfield-highlighter-class-for-flex.html
Also while hunting for solutions I came accross a generally useful class from Greensock called TextMetrics.
I'm thinking of making an application where at some points a graph is displayed that maps people over time and space. The vertical access is location, the horizontal access is time, and each person is identified by a line. At any point where the person did something of significance, there is a bigger dot on their line. Conceptually, clicking the dot brings up data about that particular dot, but clicking anywhere else on the line brings you to a detail on that person. Hypothetically, when you hover over the line the line should change color, and when you hover over a dot, just the dot should change color.
I know that I could do this pretty easily with flash, but I was wondering if these days there is any way to do this using only html and javascript. Is it possible? (Compatibility is not an issue, the only machine I am targeting is my own.)
Thanks!
You can do this with canvas, but it might be simpler to use SVG.
Since SVG uses DOM, you get builtin methods for handling events like clicking etc., instead of having to write your own handling code like you would need with canvas.
There are a few libraries that make working with SVG simpler and cross-browser compatible, such as Raphael and Dojo's dojox.gfx library.
You could create the dots as overlaid divs, so you can easily handle clicks etc. You'd have to sort out positioning quite neatly, of course.
However, highlighting the line will involve calculating the point-to-line distance manually and redrawing.