I have a TextBox in a GWT app I'm building that's used for advanced searched. I'm trying to find a way to use syntax highlighting for certain characters sequences (e.g. the string #title, or just #T) in the search string, but I can't find anything about how to allow for coloring of individual symbols. I suppose I need something more complex than just a TextBox but I'm not sure what to use. Would it perhaps be possible to do with a single-line, stripped down RichTextBox, or is there a better way?
You cannot do it with an input. Use a FlowPanel (or simply a div element), and set ContentEditable on it. Most browsers support it now. Then you can insert regular HTML tags (bold, span) inside the text on KeyUpEvent, and you can style the spans anyway you like.
Related
I am currently writing on a Plugin that uses a view with a TreeViewer. The thing is, as content for my Nodes I get plain HTML. I would like to display the HTML styled or, if not possible, the simple plain text without any HTML. But the issue I run into is that the TreeViewer is not displaying enough text.
As you can see the HTML is not completly displayed and that everyting is only one line is not pretty aswell. I would like to have a box or something that can display the text (doesnt matter if the box does not support the HTML-styling, I can do this from hand).
Currently I'm using a LabelProvider that is returning the Text of a Node as string (and from what I can see this is the only possible Option with a LabelProvider).
As workaround I could only think of cutting the text into serval nodes but I would like to know if there are better options out there ;)
If it's your own LabelProvider, you can truncate or manipulate the text shown however you wish. Since it ultimately ends up as a native control, you're basically stuck with text label with a single image (plus whatever IColorLabelProvider offers) as long as you're using a tree control.
You could experiment with the Figures from the GEF project or the Nebula CompositeTable as alternatives.
you can use a editor to show the content, this would be appropriate with your requirement. View can also be think for it. tableviewer clould also be least choice. TreeViewer generaly use to deal with hierarchical data.
There are several label providers available in Eclipse in the org.eclipse.jface.viewers package. You can choose to implement your own or extend one of them to choose your need.
Looking at the image, I would recommend to display only few words in the tree and the entire content of the node could be in a different pane/tool tip.
I need to show the function eAxn inside a JLabel, but trying to do so doesn't work and only shows as eAxn which is confusing. eAx^n could help, but that's not what I'm looking for.
Probably is because of the html version, or JLabels just dislike nested superscripts.
How else would you approach this for a JLabel?
For that specific case there exists a special-2 \u00b2.
<html>e<sup>0.5x²</sup>
The HTML editor kit, and styled text uses character attributes, which probably prevent nesting of <sup> tags. Maybe with <span style='...'> something can be done too.
I have a few records of data (less then 10). Each record consists of a few lines of text.
I want to present records to the user in a kind of grid, where user can select one of the records.
I was thinking about List component or jTable, but I couldn't make them displaying more then one line of text. What component should I use then, or how to approach this?
In subject I suggested AWT because size does matter, i.e. I want use this functionality in the applet and would like to avoid any extra libraries.
Thanks in advance
Thanks to maksimov's link I found examples of how to tackle this issue, and also very interesting link I missed somehow - http://docs.oracle.com/javase/tutorial/uiswing/components/html.html
To specify that a component's text has HTML formatting, just put the
tag at the beginning of the text, then use any valid HTML in
the remainder. Here is an example of using HTML in a button's text:
button = new JButton("<html><b><u>T</u>wo</b><br>lines</html>");
In my case it was just enough to set height of the row and add tag just before string data to be displayed. HTML tagging also let me use extra formatting, colors, etc,
Brilliant,
Thank you maksimiov
I am trying to make a simple email client in Java Swing.
I want to allow users to format their email in any way they want, like making some parts of the text bold, other parts italic, etc. In other words, I am trying to make a WYSIWYG editor. The formatting is done in HTML. I am using JEditorPane to display the text.
I have tried adding tags myself to the text directly by using setText and getText methods of JEditorPane. I could make it work for basic formatting, but it is quite difficult to handle complex formatting. (trying to remove tags from multi-tagged elements, for example)
Is there an easier way to accomplish this? I have looked at HTMLEditorKit but it seems like it does not support adding tags to and/or replacing a specific string.
Thanks in advance.
The HTMLEditorKit comes with some default Actions that allow you to do some basic styling of the text with the click of a menu item (or button). Take a look at the example in the section from the Swing tutorial on Text Component Features.
I want to implement list like "stackoverflow question list" (where each row has multiple items, text, tags, user, time etc) in GWT. What should be most appropriate approach?
I tried using FlowPanel and inside that "HTML elements" so result will be DIVs inside DIV.
But, then CSS is pain.. (unable to set right aligned multiple rows and left aligned user profile image etc)
If I use table then, it GWT does not support row rendering. Need to work on cell, it is again pain.
so, Any suggestions?
(Please exclude GXT or SmartGWT like other heavy weight frameworks, just want to use core GWT. )
Cheers,
The major answer here is 'it depends'.
The general way I try to approach anything with GWT is to come up with an HTML mockup. Once you have a static version of the layout you want, complete with CSS, it's actually quite straightforward to convert this into GWT code. See this article on 'tags first gwt' for well written example.
The point to keep in mind with GWT is that ultimately, the browser is going to have to deal with a DOM structure you build up, so if you can make it correct without GWT, it is far easier to then make it correct with GWT.
Use DockPanel for contents like multiple items, text, tags, user, time etc...Then add the dockpanel to FlexTable.FlexTable will support to add rows.
How About gwt Grid? even that supports text and table.