I have a problem with my code using zk components.
I am trying to make a popup window without zul file but compose it within my java code.
This is the sample of the code of mine
#Listen("onClick = #btnPopUp")public void popUp(){
Window win = new Window();
win.setId("winPop");
/* i compose some rows, label and other component here...*/
win.doModal();
}
When i click the btnPopUp button, i got an error message ERROR org.zkoss - >> org.zkoss.zk.ui.SuspendNotAllowedException: Not attached, <Window null#winPop>
I got a clue to use Executions.createComponents() method. But is this method can really help? because i usually use this method with a zul file for ex: Window win = (Window) Executions.createComponents("myZul",parent, map);
Thanks guys, really appreciate your help
//Sorry for my bad english :(
‘Not attached‘ is ZK's way of saying the component (the ‘Window‘) doesn't have a parent component.
win.setParent(parent);
or
parent.appendChild(win);
I believe this needs to be done before ‘win.doModal()‘ is called.
Related
when I run this code it runs error.
Checkbox term3 = new Checkbox("SENG 12213 - Data Structures and Algorithms");
term3.setFont(new Font("Arial",Font.PLAIN,13));
term3.setSize(300,20);
term3.setLocation(50,310);
term3.setOpaque(false);
when I run this code, the error is
cannot resolve the method'setOpaque(Boolen)'
how can I remove this background color,help me with this?
enter image description here
when I run this code, the error is 'cannot resolve the method'setOpaque(Boolen)'
Checkbox is an AWT component.
The setOpaque(…) method is a Swing method so you need to use a Swing component.
Use a JCheckBox.
I created one JavaFX application where I'm updating log with one background process. So I'm setting log text in TextArea and setting scroll to bottom using logs.setScrollTop(Double.MAX_VALUE). but scrollbar is set to little bit up from the bottom.
I also tried TextFlow inside ScrollPan and setting scroll to bottom using logDisplay.setVvalue(1.0). It is also giving the same result.
Platform.runLater(() -> {
logs.setText([setting log text]);//TextArea logs
logs.setScrollTop(Double.MAX_VALUE));
});
//For TextFlow inside ScrollPane
Platform.runLater(() -> {
logs.setText([setting log text]);//Text logs
logDisplay.setVvalue(1.0);
});
I also tried to run code in separate thread like
new Thread() {
public void run(){
System.out.println("called set test");
logs.setText([setting log text]);//Text logs
logDisplay.setVvalue(1.0);
}
}.start();
But nothing is working :(
Can you help me what's wrong in this?
Thanks
--Edit--
Looks like the problem is because of threading issue. Scrollbar value is updating to the previous text value. Actually while retrieving scroll value it's not retrieving latest value but it's getting older value so scrollbar set to end of the previous message, not actual last line.
I don't know the actual problem of this issue, but I found an alternative solution.
I'm setting caret's position at end of text using length of text.
logs.setText(logText);
logs.positionCaret(logText.length());
It is working for me. :)
I've been struggling with the problem in the subject for a bit longer than I'd like to admit.
I'm attempting to programatically execute the same Action that occurs when the user either clicks on the View > Collapse All button or right-clicks within the editor window and then Code Folding > Fold All.
What I tried\found so far:
The String that corresponds to the Action may be found in the enum com.mathworks.mde.editor.ActionID and is: 'collapse-all-folds'.
When the Action activates, the following method seems to be executed: org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...) (hence the netbeans tag).
This code allows me to get instances of EditorAction, ActionManager, MatlabEditor:
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = com.mathworks.mde.editor.EditorAction('collapse-all-folds');
My problem is that I can't find a way to actually activate the Action.
Any ideas / alternatives?
EDIT1: After digging a bit in "the book", I think I came even closer than before (but still not quite there). Quoting from the book:
Java GUI components often use anActionMapto store runnableActionsthat are
invoked by listeners on mouse, keyboard, property, or container events. Unlike object methods,Actionscannot be directly invoked by MATLAB.
And then a workaround is explained which involves roughly: getting some sort of an Action object; creating an ActionEvent and invoking Action's actionPerformed with the ActionEvent as an argument, as implemented below:
import java.awt.event.*;
jEd = com.mathworks.mlservices.MLEditorServices.getEditorApplication.getActiveEditor;
jAm = com.mathworks.mde.editor.ActionManager(jEd);
jAc = jAm.getAction(com.mathworks.mde.editor.EditorAction('collapse-all-folds'));
jAe = ActionEvent(jAm, ActionEvent.ACTION_PERFORMED, '');
jAc.actionPerformed(jAe);
This code runs without errors - but does (seemingly?) nothing. I suspect that I'm calling ActionEvent and actionPerformed on the wrong objects (ActionManager has possibly nothing to do with this problem at all).
P.S.
I know that there's a hotkey that does this (Ctrl + =), but this is not what I'm looking for (unless there's a command to simulate a hotkey press :) ).
After immeasurable digging, trial and way too much error - I've done it!
function FullyCollapseCurrentScript()
%// Get the relevant javax.swing.text.JTextComponent:
jTc = com.mathworks.mlservices.MLEditorServices ...
.getEditorApplication.getActiveEditor.getTextComponent();
%// Get the FoldHierarchy for the JTextComponent:
jFh = org.netbeans.api.editor.fold.FoldHierarchy.get(jTc);
%// Finally, collapse every possible fold:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(jFh);
end
or if compressed into a single, messy, command:
org.netbeans.api.editor.fold.FoldUtilities.collapseAll(...
org.netbeans.api.editor.fold.FoldHierarchy.get(com.mathworks. ...
mlservices.MLEditorServices.getEditorApplication.getActiveEditor. ...
getTextComponent()));
Note that this works on the script currently open in the editor.
Not a perfect solution but simulating the default hotkey press with java.awt.robot is possible.
...finding a way to actually fire the Action directly would be better...
import java.awt.Robot;
import java.awt.event.*;
RoboKey = Robot;
jTextComp = com.mathworks.mlservices.MLEditorServices. ...
getEditorApplication.getActiveEditor.getTextComponent;
jTextComp.grabFocus()
drawnow; %// give time for focus
if jTextComp.hasFocus()
RoboKey.keyPress(KeyEvent.VK_CONTROL);
RoboKey.keyPress(KeyEvent.VK_EQUALS);
RoboKey.keyRelease(KeyEvent.VK_CONTROL);
RoboKey.keyRelease(KeyEvent.VK_EQUALS);
com.mathworks.mde.cmdwin.CmdWin.getInstance.grabFocus; %// focus back to cmdwin
else
warning('Failed to collapse folds: Editor could not take focus')
end
I am trying to a display message when i will push save button saying that the content got saved using SWT. Can anyone please help me.
Note: I am not using Jface, Shell, Display. I am using a Composite.
Actually, you are using a Display and a base Shell. But these are hidden behind your Eclipse RCP app. I'm guessing you are creating your message dialog in the createContents(Composite) method of a ViewPart, correct?
You can access the Display with Display.getCurrent() anywhere in your code, and you can get the active Shell with parent.getActiveShell().
If you don't want to use JFace, use the MessageBox widget from SWT.
MessageBox box = new MessageBox(parent.getActiveShell(), SWT.CANCEL | SWT.OK);
box.setText("Title");
box.setMessage("This will be the message");
box.open(); // Call this on button pressed. Returns SWT.OK or SWT.CANCEL
If you want specific features for the MessageBox, you can either ask me in a comment, or check out these 18 Java code examples.
Alternatively you can use as below
MessageBox box = new MessageBox(comp.getShell(), SWT.CANCEL | SWT.OK);
Where comp is Composite.
I have problem with modal window. I call this two methods setIsModal(true) and setShowModalMask(true) but why my window isn't modal ?
Here is the Code :
Window summaryWindow = new Window();
summaryWindow.setWidth(950);
summaryWindow.setHeight(620);
summaryWindow.centerInPage();
summaryWindow.setCanDragReposition(false);
summaryWindow.setIsModal(true);
summaryWindow.setShowModalMask(true);
summaryWindow.setShowMinimizeButton(false);
summaryWindow.setTitle("Example");
summaryWindow.addItem(new Button("Example");
summaryWindow.show();
The exception you're getting is valid. In any GWT related technology, you'll find many API functionalities to set properties of GWT widget. For example, for a Window widget you have, setWidth, setHeight, centerInPage etc...
Now some of these properties MUST be applied before the widget is rendered in DOM of the browser & some of them MUST be applied after the widget is rendered in DOM of the browser.
ShowModalMask() is a property that you can set only before the widget is rendered.
centerInPage() is a property that renders Window in DOM of browser & that is the reason you're getting the exception.
Apply properties in a proper order (centerInPage() after ShowModalMask() in your case) to avoid this kind of exception.
I'm using smartgwt 2.4 : if I try your code with a button calling it enclosed in a method I get an error which indicated I cannot modify it with setModalMask (IllegalStateException - this property cannot be changed after the component has been created) .
After moving this call just after the instanciation it's working:
Window summaryWindow = new Window();
summaryWindow.setShowModalMask(true);
I don't really understand, but let me know if it's also working for you