Added tab completion to JFileChooser's File Name inputer - java

How can I add linux like tab completion to jFileChooser's File Name input field? I'm assuming I need to add a listener to the File Name's text input box to listen for the tab key. But I don't know how to do that. Then once a tab key is hit, I need to look at the directory for files/dir that start with what was inputted. Any ideas on how I can go about doing this?

Emm... I am not pretty sure what the question is but if you want to control is the textfield does contain a file name or something you can simply use JFileChooser as a panel and, as I may remember, there is a way to show/not show its components like "open"/"save"/etc buttons and, of course, replace them with your own; so there should be a way to control its input field I guess. So you need to play around UIManager
For more information you can read this , this and this
If it is not the point... so I still hope you configure your question in a more detailed manner because it is quite unclear :)
Good luck

Related

Letting user set default save directory via textfield

Im aware that there are better ways, but I need to implement it like this for this application. Its supposed to be a practice for properties too.
I bound a textProperty defaultDir from textfield inside a setDefaultDir Dialog, with the method FileChooser.setInitialDirectory(new File(defaultDir.get())); inside of my Save Dialog.
The binding itself works fine, I tested it by simply calling a printline of defaultDir right before calling setInitialDirectory(). So the problem must lie with how I input the text in my textfield.
I could not find anything on this online, usually I dont have problems googling stuff but I didnt find anything that would help me out. Since the binding seems to be working just fine, how does the user have to format the Directory in the textfield for this to work? My "C:/User/Jonas/Documents" didnt work
Thanks in advance

Making Java button dynamically?

I am new to Java and I am working on a project where depending on number of files in a directory,
buttons will be created respectively. Each button will have a customized right click context menu.
How can I achieve this or is this feasible?
I just want to know the approach to do this.
The approach that you may try:
While you iterate your directory/file list (or other process that will determine the button creation), you can generate (create an instance of) a new button (JButton), I assume you know how to use new, and put it on your form / panel.
However, most of the time, layout would become an annoying issue here.
Thus, you may try to use MigLayout to handle this.
It will help you a lot in putting your stuffs in a tidy and convenient way.
Try this approach and when you have a specific coding-part question, you can try to search the existing solution in SO (StackOverflow) or if it doesn't exist, you can ask that specific code-related question.
Hope it helps.

How disable the spinner in PrinterJob.pringDialog()?

I get the dialog for changing the properties of the print job by invoking the PrinterJob's printDialog() method without any parameter. There is a field where the user can change the the number of copies to be printed on the right-bottom of this dialog.
And now I want to disable this field (the spinner). That is only one copy to be printed and the user can't change it.
Are there any ideas for it
I don't think there is any way (or i am not aware of) to modify the native or the cross-platform Java print dialogs (last one might help you a bit). What you could do is maybe display your own dialog (without a spinner field) and under-the-hood do whatever you want (like PrinterJob.setCopies(1)).
More info i found here.
Also, have a look at the Java tutorial on PrinterJobs.

Code/text folding in SWING

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.

How can I create an AutoComplete popup in a JTextPane in Java?

I am creating a SQL editor. I am using JTextPane for the editor. I want to implement AutoCompletion for table name etc. like Eclipse.
I think the appropriate class for displaying info on top of another component is JPopupMenu, which already handles layering correctly to display itself. JPopupMenu has a show() method that takes its 'parent' component as an argument, and it will show itself in that component's coordinate space. Since you want to display a selection of terms for the user to choose from, a menu seems appropriate.
To check for text changes, you'd add a DocumentListener to the document that's wrapped by the JTextPane; you can access it using getDocument().
To find out where the cursor (actually, the caret) is, you can use getCaretPosition(). That returns the caret's position within the text stream as an int. You can use modelToView() to translate that position to actual (x,y) coordinates. That in turn will tell you where to show your menu.
You can use addKeyListener() to catch keyboard events on your JTextPane, like hitting Ctrl-Space.
The combination of all that should allow you to do what you're looking to do.
You can also use http://fifesoft.com/autocomplete/. You can install it on any JTextComponent.
For things like this you probably should consider layered panes so your auto-complete suggestions appear in the correct place and z-order.
Furthermore you will have to look for changes in the JTextPane to know when the user is typing and you will need a parser that understands what is typed so you can offer the feature only at appropriate points.
It's not quite clear what exactly your problem is and what you got so far.
I achieved this by adding a key listener to the JTextPane and checking for CTRL + Space keystrokes. When the appropriate key combo was detected the listener went off and looked up the list of possible matches based on the characters directly to the left of the cursor at the time of the key press and found the best matches and displayed them to the user in a JPopup. If there was an exact match then it simply replaced the partial text with the match. If no matches were found an option was given to the user to add the text that they had already typed, edit it and record it into the list of acceptable data.
We use jide. They have a lot of components that help you do this kind of thing really easily

Categories

Resources