JAVAFX - tree happening - menu

I have a good working JavaFX tree, with menus on it.
>File
new file
open file
.........
I have a listener, which listens every change and reacts something if the user click on an item.
It is working properly:
public void changed(ObservableValue observable, Object oldValue,
Object newValue) {
TreeItem<String> selectedItem = (TreeItem<String>) newValue;
String actualmenu;
actualmenu = selectedItem.getValue();
if ("New Project".equals(actualmenu)){
// I make a new scene...
}
But my only problem is that this Treemenu shows the "submenus", only if I click on the little Triangle which is next to the menu name (>File)
I would like to set the "File" menuitem, to show it's submenus if I click to itself, not just the triangle. It would be something this:
public void changed(ObservableValue observable, Object oldValue,
Object newValue) {
TreeItem<String> selectedItem = (TreeItem<String>) newValue;
String actualmenu;
actualmenu = selectedItem.getValue();
if ("File".equals(actualmenu)){
// open your subs in the tree, show me your submenus! What do I have to write here?
}
Does anyone have idea what to write overthere?
Thank you!

Related

How to move an Object to a specific location with a Button in Unity?

I'm new to Unity and am currently using Unity2D. What I want to do is that when a button is pressed an object moves and goes to a specific location. Currently I'm using:
public class MoveCard : MonoBehaviour
{
public float speed = 20f;
public Rigidbody2D rb;
public Vector2 pos = new Vector2(5,1);
void Update(){
}
void CardMovement(){
rb.MovePosition(pos * speed * Time.deltaTime);
}
}
I want the function CardMovement to initiate when I press a button, but it's not showing up in the Button Inspector and I don't know how to reference a Rigidbody2D in a button. How do I do this?
In the inspector in the buttons 'OnClickEvent' menu, click the plus button, drop in the object that contains 'MoveCard' component. In the drop box on the right find the method 'CardMovement'. Just a note in your current code you have it set up so if you press the button it will move only one frame's worth of movement. You could change to something like this:
public class MoveCard : MonoBehaviour
{
public float speed = 20f;
public Rigidbody2D rb;
public Vector2 pos = new Vector2(5,1);
public bool moving = false;
void Update(){
if (moving) {
rb.MovePosition(pos * speed * Time.deltaTime);
}
}
void CardMovement(){
moving = true;
}
}
edit (still not a bad idea):
//..
void FixedUpdate()
{
if (moving) {
rb.MovePosition(pos * Time.fixedDeltaTime);
}
}
//..
edit edit: set isKinematic to true on the rigidbody
The function your button is calling should be public.
public void CardMovement(){
rb.MovePosition(pos * speed * Time.deltaTime);
}
}
After you change it, assign again the object that has the script and try.
what you have to do is make a function in a script and apply that script to a game object. after making that create the button and click on the add function button to the button and drag the gameobject into the open section. afterwards chose the function from the listed scripts you added and have it call the move object script or whatever you called it.

Primefaces Tree dragdrop Event

Is there a way to keep the current dragging TreeNode as a variable?
I am using drag-drop functionality at trees but I want to undo the dragdrop event at some situations.
Aaand TreeDragDropEvent is not giving me my needs like dragNodePreviousParent and dragNodePreviousRowNumber
I tried "select" event but when a node drags, this event doesnt invoke.
Can you please help me?
//my try
public void onNodeSelect(NodeSelectEvent event){
parentNode=selectedNode.getParent();
selectedRowNumber=parentNode.getChildren().indexOf(selectedNode);
}
//TreeDragDropEvent that doesnt provide my needs
public void onDragDrop(TreeDragDropEvent event) {
TreeNode dragNode = event.getDragNode();
TreeNode dropNode = event.getDropNode();
int dropIndex = event.getDropIndex();
}

Popup window Label is not getting loaded

1.Trying to display exception message in popup window. Exception message is not appearing.
2.Eg: When i click button a popup window (Second fxml file) is to load with proper exception message in the label
3.Popup window is appearing, But the Label is not loading (Bold one --> ExceptionLabel.setText("Please enter Proper file path")) it says null pointer exception.
4.I am not sure what i missing. Same declared in FX:ID and also in second fxml file linked the main controller. Thanks in advance.
#FXML
public Label ExceptionLabel;
Stage PopupWindow = new Stage();
public void Buttonhandle(ActionEvent event) throws IOException {
try {
if(ESBOutboundFile!=null && OutputFile!=null){
String Output = SBlogpaser.Logpaser(ESBInboundFile,ESBOutboundFile,OutputFile);
System.out.println(Output);
}else{
Window(PopupWindow);
**ExceptionLabel.setText("Please enter Proper file path");**
}
} catch (Exception ex) {
System.out.println(ex);
}
}
public void Window(Stage Popup) throws Exception {
this.Popup=Popup;
final FXMLLoader fxmlLoader = new FXMLLoader();
Parent root= fxmlLoader.load(getClass().getResource("POPUPWindow.fxml"));
Scene scene1 = new Scene(root);
Popup.setScene(scene1);
Popup.show();
}
If i keep the label in "OK" handle button it is getting displayed.
From where are you expecting ExceptionLabel to be instantiated?
Assuming you are pointing the fx:controller attribute of the root of your POPUPWindow.fxml file to the current class, it will just create a new instance of that class, and inject values into that instance. The field ExceptionLabel in the current instance won't be initialized.
You could probably just about make this work by setting the controller of the FXMLLoader to the current object, something like this:
public void window(Stage popup) throws Exception {
this.popup=popup; // why?
final FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("POPUPWindow.fxml"));
fxmlLoader.setController(this);
Parent root= fxmlLoader.load();
Scene scene1 = new Scene(root);
popup.setScene(scene1);
popup.show();
}
and then remove the fx:controller attribute from POPUPWindow.fxml.
This seems like a really bad idea, though, because now the current object is acting as a controller for two different FXML files. This will be confusing at best, and under fairly reasonable conditions would produce weird results. It would be much better to write a different controller class for the popup:
public class PopupController {
private final String message ;
#FXML
private Label exceptionLabel ;
public PopupController(String message) {
this.message = message ;
}
public void initialize() {
exceptionLabel.setText(message);
}
}
and then use the window(...) method above, but with
fxmlLoader.setController(new PopupController("Please enter Proper file path"));
Obviously, if you're reusing the window(..) method, you might want to pass the message in as a parameter to that method.

How to do an action when a LWUIT List item clicked

I have a LWUIT application that has a list which involving some items.
The list itself has been added to a Combobox .
1/ How I change the colour of an item of list when I focus on it?
final com.sun.lwuit.List mylist = new com.sun.lwuit.List();
mylist.addItem("one");
mylist.addItem("two");
mylist.addItem("three");
mylist.addItem("four");
final com.sun.lwuit.ComboBox combo = new com.sun.lwuit.ComboBox (mylist.getModel());
final com.sun.lwuit.Form ff = new com.sun.lwuit.Form();
ff.addComponent(combo);
2/ I want to do an action when I click ( or double click ) on an item ,
ActionListener interface didn't make that for me , can someone guide me?
mylist.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent ev)
{
System.out.println("java");
}
}
);
You Should set a renderer to ComboBox and can use both of setRenderer and setListCellRenderer but setListCellRenderer is
deprecated than use setRenderer:
combo.setRenderer(new ListCellRenderer() {
public Component getListCellRendererComponent(List list, Object value, int index, boolean isSelected) {
Label l = new Label(String.valueOf(value));
l.getStyle().setBgColor(0xffaa00);
return l;
}
public Component getListFocusComponent(List list) {
Label l = new Label(String.valueOf(list.getSelectedItem()));
l.getStyle().setBgColor(0x00ff00);
return l;
}
});
this working well.
To change the colour of a ComboBox you should modify the ComboBoxFocusstyle from the ResourceEditor.
If you are adding the list to the ComboBox, I think that you should put the ActionListener to the ComboBox not to the List as you are doing. Try this facts.
You can work with ListCellRenderer. Its helpful tool ,
look here for example
You can implement getListCellRendererComponent(..)- this function return the compenents that display on screen and responsible on UI.
If you work with ListCellRenderer you can use actionLisiner like this:
mylist.setRenderer(getListCellRenderer());
ActionListener chooseItemActionListener = new ActionListener() {
public void actionPerformed(ActionEvent evt) {
doAction(getSelected());
}
};
mylist.addActionListener(chooseItemActionListener);

filter look up in dialog

I Have created a dialog in a class, the dialog method is as below
static void dialog(Args _args)
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
CustInvoiceTable custInvoiceTable;
;
custInvoiceTable = _args.record();
dialog = new Dialog("Change State");
dialogFieldCurrentState = dialog.addField(TypeID(State_LT),"Current State: ");
dialogFieldCurrentState.value(custInvoiceTable.State);
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(State_LT),"New State: ");
if (dialog.run())
{
custInvoiceTable.State = dialogFieldNewState.value();
}
}
in my dialog there are two fileds Current State and New State .Now when i select the New State the list of all
states is displayed(irrespective of country) which i dont want. Only the states respective of country has to be shown
in the lookup
. I need to make use of a filter something like e.g. while select while select AddressState
where addressState.CountryRegionId == custInvoiceTable.CountryRegionId; so that only states which
are related to a country is shown.
State_LT here is an string EDT (where i put in the relation of State_LT) State_LT == AddressState.StateId
IN AdressState there is a method lookupStateId(), How to call it from a dialog(code above)
?
I am answering to your last question: "IN AdressState THERE IS A METHOD lookupStateId(), HOW TO CALL IT FROM A DIALOG(code above) ?" - by the way writing in capital letters doesn't help people understand your point better.
It is not clear why your dialog is a static method, anyway you'd need the following.
Let's say your ClassDeclaration looks something like this:
class TestClass1 extends RunBase
{
Dialog dialog;
DialogField dialogFieldCurrentState;
DialogField dialogFieldNewState;
// etcetera
}
Your dialog is something like this:
public Object dialog()
{
;
dialog = super();
dialogFieldCurrentState = dialog.addField(TypeID(AddressStateId),"Current State: ");
dialogFieldCurrentState.enabled(false);
dialogFieldNewState = dialog.addField(TypeID(AddressStateId),"New State: ");
dialogFieldNewState.lookupButton(FormLookupButton::Always); // If needed
return dialog;
}
To implement a lookup the way you want it you need to do two things. First, open the dialog, right click on the New State, click Setup, and check the control's System Name. If for example it is Fld2_1 then you need to create the following method:
void fld2_1_lookup()
{
Object control = dialog.formRun().controlCallingMethod();
;
AddressState::lookupStateId(control, dialogFieldNewState.value());
}
Second, it is necessary to override the following method:
public void dialogPostRun(DialogRunbase _dialog)
{
super(_dialog);
_dialog.dialogForm().formRun().controlMethodOverload(true);
_dialog.dialogForm().formRun().controlMethodOverloadObject(this);
}
That should do the trick. I haven't done it for a while but I don't think I forgot something.
Example of looking up customer in dialog:
For example, to have a customer choice dropdown in the dialog,
In report class declaration method --->
DialogField CustomerDlg;
CustAccount customer;
In the reports dialog method: ----->
dialog.addGroup("Customer");
CustomerDlg = dialog.addField(typeid(CustAccount));
CustomerDlg.value(customer);
In the getFromDialog method: ---->
...
customer = CustomerDlg.value();

Resources