I have a simple JavaFX app that allows the user to query a database and see the data in a table.
I'd like to allow the user to be able to click a table cell and copy text from that cell to the clipboard with the standard clipboard key stroke: ctrl-c for Win/Linux or cmd-c for Mac. FYI, the text entry controls support basic copy/paste by default.
I'm using the standard javafx.scene.control.TableView class. Is there a simple way to enable cell copy? I did some searches and I see other people create custom menu commands... I don't want to create a custom menu, I just want basic keyboard copy to work with single cells.
I'm using single selection mode, but I can change to something else if need be:
TableView<Document> tableView = new TableView<Document>();
tableView.getSelectionModel().setCellSelectionEnabled(true);
tableView.getSelectionModel().setSelectionMode(SelectionMode.SINGLE);
You just have to create a listener in the scene, something like:
scene.getAccelerators()
.put(new KeyCodeCombination(KeyCode.C, KeyCombination.CONTROL_ANY), new Runnable() {
#Override
public void run() {
int row = table.getSelectionModel().getSelectedIndex();
DataRow tmp = table.getItems().get(row);
final Clipboard clipboard = Clipboard.getSystemClipboard();
final ClipboardContent content = new ClipboardContent();
if(table.getSelectionModel().isSelected(row, numColumn)){
System.out.println(tmp.getNumSlices());
content.putString(tmp.getNumSlices().toString());
}
else{
System.out.println(tmp.getSelected());
content.putString(tmp.getSelected());
}
clipboard.setContent(content);
}
});
For a complete example, you can download it at the gist.
I recommended that you review this post, work for me
http://respostas.guj.com.br/47439-habilitar-copypaste-tableview-funcionando-duvida-editar-funcionalidade
The author use an aditional util java class for enable the cell content copy from a tableView
Related
so I am using JavFX to create a form that stores all the answers in a csv file. I need to create a dropdown menu that allows the users to select an option, which is then recorded in the csv file. I have tried a lot of different options, however I think comboBox is the best option.
I have no problem creating the ComboBox, I only run into problems when it comes to the method to get the value of the box.
Can someone help me find a solution, or suggest what another JavaFX menu I can use?
This is the code I have right now:
public VBox setFamiliar(){
Button button = new Button();
button.setOnAction(e -> toString());
familiarComboBox = new ComboBox<>();
familiarVBox = new VBox();
familiarComboBox.getItems().addAll("Irmão", "Irmã", "Avó", "Avô", "Tio", "Tia", "Pai", "Mãe");
familiarVBox.getChildren().add(familiarComboBox);
familiarVBox.getChildren().add(button);
return familiarVBox;
}
Here I set the ComboBox, this part doesnt seem to have a problem because it appears and I can select an item. I created a separate void toString() method that sets the value of a variable to the current selected item
public void toString(ActionEvent e){
familiar = familiarComboBox.getSelectionModel().getSelectedItem().toString();
}
The problem is then in the get method to get the value that was selected.
public String getIrmao(){
if(familiar.equals("Irmão")){
return "2";
}
return "0";
I also tried to do familiarComboBox.getSelectionModel().getSelectedItem().equals(), and other variations of this combination.
If I understand your requirement -- that when a user makes a choice from the "Familiar" combo box, a value should be written immediately to a CSV file -- you don't need the getIrmao() method. You simply write the value out in the action which you are calling toString(...) (not a good choice of names), but which we will rename to handleFamiliarChange(...).
Now the method becomes
public void handleFamiliarChange(ActionEvent e){
final String familiar =
familiarComboBox.getSelectionModel().getSelectedItem().toString();
FileUtils.writeToCsvFile(familiar.equals("Irmão") ? 2 : 0);
}
where FileUtils.writeToCsvFile(...) is a method that does the file writing. Note that FileUtils is a class you have created to separate out file handling concerns -- your JavaFX view class should only concern itself with views.
I'm after something like the application output window in Visual Studio, like so:
I'd like to be able to:
bind to an ObservableCollection of strings
select and copy text (as shown in the screenshot above)
At present this is for a Mac app, although iOS may follow later.
I've tried these:
Editor - Problem is it only exposes a Text property that I can bind to and not a collection. Sooner or later, the maximum string length will be reached.
ListView with Label for ViewCell - Problem is text from a Label is not selectable, let alone having multiple lines (bound collection items) selectable.
Using a custom renderer for Mac that makes use of NSTextView and appending to textStorage every time a new item is added, but again, there’s a limit to how much you can add to textStorage.
I'm open to using third-party tools such as Syncfusion, if that makes it easier.
Custom a method to deal with list data to combine them into a newline string :
public string formatstring(NSArray objects)
{
StringBuilder stringBuilder = new StringBuilder();
for(nuint i=0;i< objects.Count; i++)
{
stringBuilder.Append(objects.GetItem<NSString>(i) +"\n");
}
return stringBuilder.ToString();
}
Then used in NSTextView as follow :
string[] items = new string[] {"111111" , "222222" , "333333" , "444444" , "555555" };
NSArray array = NSArray.FromStrings(items);
NSTextView textView = new NSTextView(new CGRect(100,160,200,100));
textView.BackgroundColor = NSColor.Gray;
textView.Value = formatstring(array);
View.AddSubview(textView);
The effect :
I am creating a pdf where the title of each pdf page would be customized based on the current page number. For example, in the 1st page the title is "First Page", and in the 2nd page the title is "Second Page", and so on...
What we do now is we add the title to a PdfPTable, then we add a lot of other stuff to the PdfPTable as well, so this PdfPTable contains several pages of data. Finally we add this large PdfPTable object to document. Now we want to use the onStartPage() method in PdfPageEventHelper to get the current page number so that we can customize the title for each page.
The problem is onStartPage() does not trigger until we add that large PdfPTable object to the document, which means we cannot make the resource bundle to load different key values before the PdfPTable object is added to the document, right? Any suggestion to realize this?
--------------------we have codes like below-------------------------------------
Phrase title = new Phrase();
title.add(new Chunk(bundle.getString(pdfNewPageEventHandler.getKey()), headerFont));
PdfPCell cell = new PdfPCell(new Paragraph(
new Phrase(title)));
.........
PdfPTable table = new PdfPTable(tableSize);
table.addCell(cell);
.........
document.add(table);
private class PdfNewPageEventHandler extends PdfPageEventHelper {
private int currentPageNum = 0;
private String key;
#Override
public void onStartPage(PdfWriter writer, Document document) {
currentPageNum = currentPageNum + 1;
if (currentPageNum == 1) {
key = "firstPage";
}
else if (currentPageNum == 2) {
key = "secondPage";
}
}
public String getKey() {
return key;
}
}
I have more than one answer. I don't know which one applies to your specific situation:
Don't ever add content in the onStartPage() method. As documented, all content should be added in the onEndPage() method.
It's not always wise to create one large table (it builds up in memory) and then add the table to the document (only at this moment, memory can be freed). Maybe you want to try out some of the large table strategies from the documentation.
In some cases, building a table in memory and then adding it to the document is the only strategy you can use. iText will then distribute the content of the table over different pages, triggering page events. However: if you want to trigger events that are specific to the table, you can also define events at the level of the table. There's a PdfPTableEventSplit and a PdfPTableEventAfterSplit class for this exact purpose.
The code sample you provided, didn't really illustrate the problem. Can you please rephrase the problem, as I'm not sure if any of my answers go to the core of the problem.
I'm creating a basic CSV importer tool. The goal is for a RunBase class to call a dialog, and in the dialog, I want to have the user select a CSV file that will be a specific format.
I have dialog.allowUpdateOnSelectCtrl(true) so the idea is when they choose a file, I can read in the first row and create a preview in a listview the same way as the Data Import/Export tool does.
This is all my dialog is so far:
public Object dialog()
{
DialogRunbase dialog = super();
container conFilter = ["Comma Seperated Value .txt ", "*.csv"];
#resAppl
;
dialog.filenameLookupFilter(conFilter);
dialog.allowUpdateOnSelectCtrl(true);
dlgFileName = dialog.addFieldValue(typeid(filenameSave),filenameSave);
return dialog;
}
I realize that I could create a custom form and other options. I'd like to try and do it this way so I can learn this method.
I made a basic text editor that lets users insert predefined strings into the document with button clicks. What I need to do now is let the user define their own buttons and string values.
For example I have a button that inserts "Hello" into the text. The user may want to create a button that adds "Goodbye".
To accomplish this I figured I would create a .txt file called buttons.txt or something. i would readutfbytee, loop through it to create the buttons. problem is I know what I want to do but not sure where to start. Can someone give me a kick start?
Please check the following code as the simple way to externalize your button settings:
/*
buttons.txt content sample:
Helo=Hello World&Test=Test Inserted
*/
protected function loadSettings():void
{
var varLoader:URLLoader = new URLLoader();
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, onSettingsLoaded);
varLoader.load(new URLRequest("data/buttons.txt"));
}
protected function onSettingsLoaded(event:Event):void
{
var varLoader:URLLoader = URLLoader(event.target);
var varButtons:URLVariables = varLoader.data;
var buttons:Dictionary = new Dictionary();
for(var label:String in varButtons{
buttons[label]=varButtons[label].toString().split(",");
}
//use parsed buttons dictionary
}
For starters you need to decide how you are going to store that data that the user enters.
A flex web app can't save any files to the server, so if you want to save this across multiple computers, you'll need a server to do the data saving / retrieval.
If you want to store the buttons just temporarily, and unique to one computer, you can stuff them into a SharedObject.
After you decide this, then you can get more specific on a question of how to do exactly what you're wanting.