vaadin grid inline editor not working - java

can someone please help me im a little bit flustered:
Im trying to just simply display a vaadin grid with 2 columns an test data an do an inline editing of the data.
But the Editor isn't shown correctly in the browser
Grid grid = new Grid();
grid.setCaption("Double click to edit");
grid.setSizeFull();
grid.setEditorEnabled(true);
grid.setSelectionMode(SelectionMode.NONE);
grid.addColumn("index", Integer.class).setRenderer(new NumberRenderer("%02d")).setHeaderCaption("##")
.setExpandRatio(0).setEditable(false).setWidth(50);
grid.addColumn("name", String.class).setExpandRatio(2);
Slider progressEditor = new Slider();
progressEditor.setWidth(100.0f, Unit.PERCENTAGE);
progressEditor.setMax(150.0);
progressEditor.setMin(1.0);
grid.addColumn("progress", Double.class).setRenderer(new ProgressBarRenderer() {
#Override
public JsonValue encode(Double value) {
if (value != null) {
value = (value - 1) / 149.0;
}
return super.encode(value);
}
}).setEditorField(progressEditor).setExpandRatio(2);
that's just the sample code from the vaadin demo page im using here.
But the output is this:
Anyone got the same problem or something similar an can help me out here?
regards
flo

Related

Need help in retrieving text of a tooltip with Selenium and Java

I am trying to get the text of the tooltip in the following image - with the code snippet shown below.
String xPath = "//div[#class="tooltip-inner"]/div";
we = driver.findElement(By.xPath(xPath));
if (null != we) {
Actions action = new Actions(driver);
action.moveToElement(we).moveToElement(driver.findElement(By.xpath(xPath))).click().build()
.perform();
String actualText = we.getText();
} else {
....generate an error
}
The code does not throw an error, but at the same time, text is not retrieved.
I tried to locate the /p and the /ul child elements and get their texts - but no luck either.
What am I not doing right? Any ideas?
Thanks.
-S-

swing component not fully functioning into javafx application

I have two separate based on Swing and Javafx. Now i need to open Swing application inside Javafx Tab pane by below code
SyntaxTester ob = new SyntaxTester(filepath);
SwingNode swingnode = new SwingNode();
JComponent jcomp = new JComponent() {
};
jcomp.add(ob.getContentPane());
swingnode.setContent(jcomp);
BorderPane borderpane = new BorderPane(swingnode);
tab.setContent(borderpane);
Basically this Swing application is JEditorPane based editor. Swing application is added and working successfully inside Tab pane but the issue is that, there is hinting feature and after selecting text from hint, editor looses it's cursor and user again manually click on the editor. Although Swing application separately working fine. Please help me with resolve it. Thanks in advance.
This is what happening when user select from hint list.
if (jLstItems.getSelectedIndex() >= 0) {
result = jLstItems.getSelectedValue().toString();
} else {
result = jTxtItem.getText();
}
char pressed = evt.getKeyChar();
if (pressed != '\n') {
result += (pressed == '\t') ? ' ' : pressed;
}
setVisible(false);
target.replaceSelection(result);

JTable get value from cell when is not submitted

I would like to get value from cell when its is no submitted (cell is in edit mode) - "real time"; Is it possible?
I tried this but it is working only if i submit data - press enter
int row = jTable.getSelectedRow();
int col = jTable.getSelectedColumn();
String cellValue = jTable.getValueAt(row, col).toString();
I want to get on keypress cell value without exiting it, get this text real time while typing
KeyboardFocusManager.getCurrentKeyboardFocusManager().addKeyEventDispatcher(new KeyEventDispatcher() {
#Override
public boolean dispatchKeyEvent(KeyEvent e) {
int row = jTable.getSelectedRow();
int col = jTable.getSelectedColumn();
if (e.getID() == KeyEvent.KEY_RELEASED) {
if (jTable.isEditing())
jTable.getCellEditor().stopCellEditing();
String cellValue = (jTable.getValueAt(row, col)!=null) ? jTable.getValueAt(row, col).toString() : "";
System.out.println(cellValue);
}}
jTable.getCellEditor().stopCellEditing() - cause ugly in/out animation while typing
#camickr Sorry for the confusion. Your solution is ok.
I just needed to add jTable.editCellAt(row, col); to get back into edit mode.
Thanks again
cell is in edit mode
The editing must be stopped before the value is saved to the model.
The easiest way to do this is to use:
JTable table = new JTable(...);
table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
when you create the table.
Now when you click on the button to do your processing the table loses focus so the data is saved.
Check out Table Stop Editing for more information.

JTextPane - HTMLDocument: when adding/removing a new style, other attributes also changes

I have a JTextPane (or JEditorPane) in which I want to add some buttons to format text (as shown in the picture).
When I change the selected text to Bold (making a new Style), the font family (and others attributes) also changes. Why? I want to set (or remove) the bold attribute in the selected text and other stays unchanged, as they were.
This is what I'm trying:
private void setBold(boolean flag){
HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectedText().length();
StyleContext ss = doc.getStyleSheet();
//check if BoldStyle exists and then add / remove it
Style style = ss.getStyle("BoldStyle");
if(style == null){
style = ss.addStyle("BoldStyle", null);
style.addAttribute(StyleConstants.Bold, true);
} else {
style.addAttribute(StyleConstants.Bold, false);
ss.removeStyle("BoldStyle");
}
doc.setCharacterAttributes(start, end, style, true);
}
But as I explained above, other attributes also change:
Any help will be appreciated. Thanks in advance!
http://oi40.tinypic.com/riuec9.jpg
What you are trying to do can be accomplished with one of the following two lines of code:
new StyledEditorKit.BoldAction().actionPerformed(null);
or
editorPane.getActionMap().get("font-bold").actionPerformed(null);
... where editorPane is an instance of JEditorPane of course.
Both will seamlessly take care of any attributes already defined and supports text selection.
Regarding your code, it does not work with previously styled text because you are overwriting the corresponding attributes with nothing. I mean, you never gather the values for the attributes already set for the current selected text using, say, the getAttributes() method. So, you are effectively resetting them to whatever default the global stylesheet specifies.
The good news is you don't need to worry about all this if you use one of the snippets above. Hope that helps.
I made some minor modifications to your code and it worked here:
private void setBold(boolean flag){
HTMLDocument doc = (HTMLDocument) editorPane.getDocument();
int start = editorPane.getSelectionStart();
int end = editorPane.getSelectionEnd();
if (start == end) {
return;
}
if (start > end) {
int life = start;
start = end;
end = life;
}
StyleContext ss = doc.getStyleSheet();
//check if BoldStyle exists and then add / remove it
Style style = ss.getStyle(editorPane.getSelectedText());
if(style == null){
style = ss.addStyle(editorPane.getSelectedText(), null);
style.addAttribute(StyleConstants.Bold, true);
} else {
style.addAttribute(StyleConstants.Bold, false);
ss.removeStyle(editorPane.getSelectedText());
}
doc.setCharacterAttributes(start, end - start, style, true);
}

Getting my scrollPane to scroll under programatic control

I have a Groovy app which uses a scrollPane built via swing builder:
BinsicWindow(def controller)
{
controlObject = controller
swinger = new SwingBuilder()
mainFrame = swinger.frame(
title: "Binsic is not Sinclair Instruction Code",
size:[640, 480],
show:true,
defaultCloseOperation: WindowConstants.DISPOSE_ON_CLOSE){
scrollPane(autoscrolls:true) {
screenZX = textArea(rows:24, columns:32) {visble:true}
}
screenZX.setFont(new Font("Monospaced", Font.PLAIN, 18))
}
}
I add text to the textArea programatically (i.e. no user input) and I would like the textArea to scroll down automatically as content is added. But the view remains fixed at the top and I can only see the bottom (once the screen is more than full) by dragging the mouse.
Can I fix this? I have been searching for an answer to this for a wee while now and getting nowhere. Apologies if it's a simple answer.
The following lines should scroll your textarea to the last text position:
rect = screenZX.modelToView(screenZX.getDocument().getLength() - 1);
screenZX.scrollRectToVisible(rect);

Categories