I need to add some items to the default context menu of a text control in SWT, but already found out I cannot modify this menu and have to create a new one from scratch.
But how do I emulate the default functions Undo, Cut, Copy, Paste, Delete? Do I really have to re-implement all this Clipboard stuff for myself? And I don't even know how to access the Undo history of the control. Is there some maybe dirty hack to emulate the key codes that achieve the functionality?
The StyledText has built-in support for Cut, Copy & Paste:
StyledText editor = new StyledText(...);
editor.invokeAction(ST.CUT);
editor.invokeAction(ST.COPY);
editor.invokeAction(ST.PASTE);
As for the Undo operation, I'm afraid you'll have to implement it yourself. SWT doesn't have anything useful here, AFAIK. Here's a good start if you want to do it yourself: SWT Undo Redo.
I already found out that I can use the functions cut(), copy() and paste() on a Text control. Sadly, undo() is not available.
I now emulate undo by sending CTRL-Z (CTRL-Y on your US-Keyboard) to the app.
Related
I've created a CCombo object. I've added an AccessibilityControlListener and overridden the getRole(AccessibleControlEvent e) method. The code inside the method is
e.detail = ACC.ROLE_COMBOBOX;
But the screen reader(JAWS) still reads the CCombo as edit read only. But it should read combo box since i've overridden the default role. But it dosen't seem to work. Furthermore, the CCombo object doesn't even respond to the overridden accessiblitylistener or accessibilitycontrollistener methods.
(this is not exactly an answer, but the comment field ran out of space)
Other than most SWT widgets, CCombo isn't a native widget. Instead it is composed of other (native) widgets, namely a Text, a Button and a List. Apparently, not all accessibility events are overridden or redirected to the right widget.
The SWT Bugzilla lists several issues with CCombo and accessibility (search for 'ccombo accessibility'). Looking a the age and activity of the bugs it seems unlikely that they will be fixed anytime soon.
You might be better off using the (native) Combo widget if that's an option for you.
Depending on how desperate you need a fix, you could also write your own CCombo and fix the accessibility issues there. Of course only if all CCombos are created by your code.
Knowing the internal structure of the widget, you could also attach appropriate accessibility listeners to the respective children (Text, Button, List) if that's enough to fix your issues.
I have a SWT button (with SWT.CHECK flag) and SWT Text.
Upon pressed, SWT button should enable/disable the wrapping of the SWT text.
I am aware that text wrapping capability is specified in the constructor as follow:
new Text(parent, SWT.WRAP)
But I couldn't find a method such as setWrap(false) to programmatically enable/disable it in runtime.
Is there a way to do this in SWT?
Or the only solution is to dispose the old text, and create a new one with different flag?
In general SWT styles can't be changed and this is the case for the Wrap style of the Text control.
The StyledText control does have a setWordWrap(boolean) method, you should be able to use that.
Hi am creating an application in which I am using JTable to listing of file or folder names.
My question is:
How can I find and Search a Particular file or folder in JTable like in Windows.
In windows directory listing when we press any key then we can see that file or folder start with that character is selected and if we again press same key then next file/folder is selected with start with that character.
If you can use 3th party code, I would suggest to take a look at the SwingX project. Their JXTable, JXTree, JXList and some other classes provide an implementation of the Searchable interface, which makes creating a search widget a breeze.
And if that is even too difficult, they provide out-of-the-box a JXFindPanel which provides a UI to search a Searchable
If you can (and you're willing to) use third party UI components, the Open Source JIDE Common Layer offers a few nice components: e.g. you might like FolderChooser which has an automatic find-as-you-type functionality.
Here's the link: JIDE Common Layer. If you click the "RUN IT" button you can see a sample via Java Web Start.
I've used many JIDE components (only the open source ones) in my projects and avoided reinventing the wheel many times.
Hope this might help you.
You want an action happen when a key is typed ?
-> add a keyListener to your table
You want to know which row is valid
-> query your datamodel connected to your jtable
You want a selected row to change ?
-> in the keytyped implementation of your listener change the selection
table.getSelectionModel().setSelectionInterval(1,1);
Since I don't know something about how did you implement your code logics, JTable implemented Sorting and Filtering
but you describtions talking about JTreeTable
I would consider writing a custom TableCellRenderer, responsible for highlighting any matching letters in the String being rendered. When someone updates the search text field the simplest approach is going to then be to repaint the entire JTable to show the updated "match state" of the table cells.
I'm looking for a way to provide 'text folding' capabilities to a swing JTextArea or JTextPane
More specifically, I want to add a block of data in a text component and I want the component to display only some header line. Then the user can unfold the block by clicking some icon. This is just like the code folding feature in most IDE.
I've found ->some sample code<- after some thorough search, but the mechanisms used here are quite obscure to me and it stops working when I try to remove text from the document.
Maybe using XML as input could be a lead ?
This one how to add collapsible area
http://java-sl.com/collapse_area.html
This one how to represent XML
http://java-sl.com/xml_editor_kit.html
I would start by looking at the NetBeans API: http://bits.netbeans.org/dev/javadoc/org-netbeans-modules-editor-fold/overview-summary.html
If you were to do it yourself, you'd need to provide a Document implementation that makes the JTextComponent think that pieces are being added or removed, then attach click events that tell the document to update itself. A lot of work.
Visually, it may also be better to use JEditorPane, but that's probably more work.
Is there any way to include a Text Box inside a draw2d figure? (a code example would be nice)
Not easily, and if you're just using Draw2d without GEF, then I don't think it's possible.
With GEF, you can make use of a DirectEditManager in an Edit Part, and create an Edit Policy (extending DirectEditPolicy, installed with the key EditPolicy.DIRECT_EDIT_ROLE) to allow a direct edit to be performed on a figure.
You could create a figure which extends Label that is styled to look like a text box, and activate (by overriding performRequest in the Edit Part) editing upon selection.
This Schema Diagram example contains this type of functionality (and more importantly, the code!), although the figure used for edit (EditableLabel) isn't styled to look like a text box, and the activation itself is on double-click rather than selection.
It may point you in the right direction though.