Swing: Which objects for a multi panel display and highlighting text - java

I plan on making a multi comparison program. It will compare multiple files by displaying N number of files in a grid where N = X * Y. X and Y are the width and height of the grid elements. Easy enough, I know how to do this pretty much.
The question:
How do and in what way is best to highlight individual characters in each of these grid elements? I plan on highlighting matching text that is found in the same position.

I'd use a JTextPane rather than a JTextArea, and read up on the StyledDocument class. This will give you all sorts of options.

You could use a JTextArea with a Highlighter. See the second example on this page for how.

I'm not sure what you mean by "Highlight the characters", but to bring attention to grid elements, or pairs of grid elements, you could set the background color of the appropriate component.

Related

Expandable grid Vaadin UI

I have a simple grid. Two columns with a variable amount of rows. I want to make it so i have a header row with an arrow that can collapse and show the whole grid. So when I bring up the app, only the header row is visible with an arrow, and I can click to expand/collapse to show the rest of the grid.
A TreeGrid seems like overkill since I don’t need any hierarchical structure, just the ability to collapse/expand one row. I exclusively use IE and I’ve read that Drawyer doesnt work with IE 8 and above. I return a list of the objects and the object just has two string variables.
Any help with this? I am new to Vaadin 8.
Set grid height (workaround)
As a workaround, you could set the height to be approximately the number of pixels you expect to be the height of the header.
See the Sampler demo. Click the gear icon at top to expose properties of the example Grid object. The last property shown is "Size (W x H)". Change 100% to 100px to see the effect.
Grid height set to 100%
Grid height set to 100px
You can also hide the footer (see checkbox in that property list).
I don't think this can be done with plain Vaadin. But I recommend the following simpler approach:
Initially call grid.setHeightByRows(1.5) (javadoc). This will show exactly one row and a half to indicate more data is available. A scrollbar will appear, too.
Make a new column within the grid that has a button or add a button below the grid that - when clicked - calls setHeightByRows with the number of elements in the grid and hides the button. This will show all rows.

ListCellRenderer - JLabel - String - n rows

So I have this situation:
I have a JList that displays a bunch of Strings.
However, these strings are really long and JList is really narrow. Meaning the strings won't fit.
What I want to do is make each entry to have two rows, like this:
|Word word word |
|word word wor...|
It would do wordWrap for the first row, and then finish the secon't row by cutting the rest of the string and appeinging the three dots to what is left in a way maximum space is filled.
It doesn't really matter what I do, the important thing is that I have to use FontMetrics to measure all this stuff so I can make it work. And that's the catch.
Until whole getListCellRendererComponent(...) method is executed, the component will not be painted, thus having no graphics, thus making any font measurement impossible.
How do I get around it?
P.S. I need to use the JLabel for the visuals.
the component will not be painted, thus having no graphics, thus making any font measurement impossible.
You don't need the Graphics to use the FontMetrics.
See Left Dot Renderer which is used for a JTable, but the concepts should be the same for a list renderer as well.
You need to use JLabels? It'd be a lot easier to have getListCellRendererComponent() return a JTextArea whose height has been set to 2 lines and which has setLineWrap() and setWrapStyleWord() both set to true. Make the JTextArea uneditable, and it'll look like a 2-line JLabel.

Changing the min and max value of JSlider depanding on condition

I'm creating a Swing GUI in Netbeans. The purpose of this GUI is to open an (buffered)image (in a JLabel as icon) and apply Affine transforms on it. Now there are 4 transforms that I'm doing as follows.
Now, each transform requires two sliders to change the X and Y value, except that of rotate, which will require only one. I did it this way since its much better than having to do four tabs for all 4 types of transforms. Also I want it to be such that , for example, if an image is rotated, the same rotated image can be sheared by selecting shear from the Drop down list.
The problem is (are):
How do i repaint the label icon and apply different transform on the same repainted image?
Also, how do i change the minimum and maximum value of JSlider depanding on the effect selected?
You should store originally loaded BufferedImage, and create its copy - that way you won't "destroy" it.
As for the changing value there are methods setMaximum and setMinimum - add listener to list, as stated in Oracle tutorial and modify the values.
As a concrete example of #Daniel's answer, the article Image processing with Java 2D describes the program ImageDicer. It constructs a TreeMap<String, BufferedImageOp> each of which may be selected from a JComboBox and applied to a BufferedImage.
See also related examples here and here.

Java Swing Gridlayout: Accessing Specific Coordinate

I'm creating a Java swing GUI and I have formatted a JPanel to use a GridLayout. I need to access a specific "box" (i.e. specific coordinate) of the grid, but I cannot see a way to do so.
How can I do this?
You shouldn't depend on GUI code (the View) to give you information about program data (the model). The best solution would be to "know" which component is where from the start--maybe you should have a data structure (2D array?) that holds the components and is updated whenever something's added to the grid.
If you want a quick and very-dirty fix, though, you could start playing games with JPanel.getComponentAt(). This requires pixel coordinates, though, so you'd need to do some reverse-engineering to figure out how much space a given grid square takes up. The space between grid squares is given by your GridLayout object. This is not recommended whatsoever though. I'm just including it in the interest of completeness (and since it's a more literal response to your question).
In GridLayout, "The container is divided into equal-sized rectangles." You can add an empty, transparent component in places you want to appear empty, e.g. new JLabel(""). See also GridBagLayout and Using Layout Managers.

Overlapping vertex labels in JUNG

First of all, I am new to JUNG. I am trying to visualize trees in JUNG using the TreeLayout, but I am always faced with the issue of overlapping vertex labels. More so when the number of nodes and paths are many. Any ideas as to how to go about preventing such an overlap ?
I am aware of the vertex label renderer, but I did not get far with this either.
Here are a couple of options:
(1) Increase distx (the distance between adjacent tree leaves). This is an optional constructor argument.
(2) Use a Transformer for the rendered label that uses a substring of the label, or a shortened representation. Then separately set hover text to show the entire label.

Categories

Resources