Im trying to create a gui, it has some checkbox and another components, under the start test buton there are some tests. when i click this button, firstly,disable all checkbox, after that start all checked tests. And then enable all failed test's checkbox.
problem is that; i clicked start button, all checkbox turn disable but in code side (i show it with breakpoint)!! did not disable in gui. All tests finished, and all fail tests turn enable other success tests turn disable successfully.
here is my codes template
btnStartTests.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e){
disable_all_checkbox();
startSelectedTests();
bla_bla_bla();
}
}
how can i disable these checkboxes properly (in click start button time)?
i use SwingWorker class, it is clearly runnig as i want thanks to #JBNizet
SwingWorker<Void,Void> worker2 = new SwingWorker<Void, Void>(){
#Override
protected Void doInBackground() throws Exception {
disable_all_checkbox();
startSelectedTests();
bla_bla_bla();
return null;
}
};
Related
I have a pop-up which opens when clicking the button printName. The pop-up has a check-box. The check-box when checked prints name in the pop-up and when unchecked clears name from the pop-up.
The problem happens when the pop-up is closed and reopened. The checkbox irrespective of being default checked does not invoke the actionListener(does not print the name).
So now I am trying to invoke the printMyName function just as the pop-up is generated from the listener initialized for the pop-up (printName) button
printName pop-up structure -
public NameDisplayPanel
(
NameEvent name,
NameDisplayPanelListener listener
)
{
this.name = name;
this.listener = listener;
//Some code
}
Here is the code to invoke printMyName when the check-box is toggled -
CB = new JCheckBox("Display Selected", false);
CB.addActionListener(
new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (((JCheckBox) e.getSource()).isSelected()) CB.setSelected(true);
else CB.setSelected(false);
printMyName();
}
}
);
CB.setSelected(true); //Checks the checkbox true everytime the window reopens
// Trying to implement method to invoke printMyName everytime when NameDisplayPanel pop-up is created.
Any leads for how to implement that listener?
Sets the state of the button. Note that this method does not trigger an actionEvent. Call doClick to perform a programmatic action change.
API Java Doc
My program opens a dialog if a certain string is clicked inside a StyledText. So in the mouseDown() I first want to check what has been clicked and then open a dialog. This works. After closing the dialog the mouseUp() is not called. This leads to selecting the text when moving the cursor, as if the user tries to select a text.
I can reproduce the behavior by performing the following tasks:
Click on String in StyledText
-> Dialog Opens
Close Dialog
Move Mouse without clicking
-> Text gets marked as selected
In my use case I don't need mouseUp() to be fired. But having it not fired means the OS assumes that the mouse button is still down and selects text. This may be the correct behavior if a dialog opens and steals the focus. But than there must be a possibility to tell the system, that the mouse button has been released.
myStlyedText.addMouseListener(new MouseListener() {
#Override
public void mouseUp(MouseEvent e) {
System.out.println("MouseUp is fired");
}
#Override
public void mouseDown(MouseEvent e) {
if (certainStringClicked()) {
openDialog();
}
}
#Override
public void mouseDoubleClick(MouseEvent e) {}
});
I can verify that mouseUp() is not called because "MousUp is fired" is not printed on console.
What is the best way to handle this? I already tried to set focus on another widget (setFocus() and forceFocus()), but that didn't help.
I tried to call mouseUp myself:
Event event = new Event();
event.type = SWT.MouseUp;
event.button = 1;
MouseEvent mouseUpEvent = new MouseEvent(event);
mouseUp(mouseUpEvent);
This leads to the message "MousUp is fired", but the selection problem still exists.
I could move the code into the mouseUp() method, but that's not actually what I want. The dialog should appear immediately. What else can I do?
Try adding myStlyedText.notifyListeners(SWT.MouseUp, null); to your code.
It should work.
myStlyedText.addMouseListener(new MouseListener() {
#Override
public void mouseUp(MouseEvent e) {
System.out.println("MouseUp is fired");
}
#Override
public void mouseDown(MouseEvent e) {
if (certainStringClicked()) {
myStlyedText.notifyListeners( SWT.MouseUp, null );
openDialog();
}
}
#Override
public void mouseDoubleClick(MouseEvent e) {}
});
This is not a good solution. But it may be a workaround for some.
It is possible to add SWT.MODELESS to the shell style in the constructor of the Dialog, which extends jface.dialog.Dialog.
setShellStyle(SWT.MODELESS);
MouseUp() get's fired now.
The problem here is that it is possible to open many dialogs by clicking the text although one dialog is already open.
Trying to write a Swing GUI. When clicking a button, I want to test if the other button has already been clicked. If it has, then execute the statements in the "if" statements. But it looks like the "if" statements never execute?
private void radSingleBurgerActionPerformed(java.awt.event.ActionEvent evt) {
if(radDoubleBurger.isSelected()){
newItemPrice = Double.parseDouble(lblItemPrice.getText());
newItemPrice -= doublePrice;
lblTest.setText(String.valueOf(newItemPrice));//test to see if working
}
lblItemPrice.setText(String.valueOf(newItemPrice += singlePrice));
}
private void radDoubleBurgerActionPerformed(java.awt.event.ActionEvent evt) {
if(radSingleBurger.isSelected()){
newItemPrice = Double.parseDouble(lblItemPrice.getText());
newItemPrice -= singlePrice;
lblTest.setText(String.valueOf(newItemPrice));//test to see if working
}
lblItemPrice.setText(String.valueOf(newItemPrice += doublePrice));
}
Clicking a JButton does not make it (permanently) selected. Clicking is only a temporary action.
Maybe you want to use a JToggleButton. This allows you to click a button to make it selected and then click it again to make it unselected.
Read the section from the Swing tutorial on How to Use Buttons for more information.
Or if you just want to know if the user has clicked on a regular JButton, then you will need to maintain a Boolean variable yourself that you update in the ActionListener of the button.
I'm trying to figure out how to make it so that my navigation menu, when clicked, will open appropriate panels within my GWT page.
Here's a part of my code:
#Override
public void onModuleLoad()
{
MainNavBar nb = new MainNavbar();
NavItem i = new NavItem("1", "TestNavItem");
nb.add(i);
i = new NavItem("2", "TestNavItem2");
nb.add(i);
}
So when I run the project, I see that I have a menu on the test site:
So my question is, how can I have an event handler such that when either one of those are clicked, the panel to the right will be changed to something else?
Thanks!
create an actionListener class,
public class listen implements actionListener{
public void actionPerformed(ActionEvent e){
if(e.getSource() == ObjectName){
// Your code goes here....
}
}
}
then create an object of this class e.g
listen listener = new listen();
YourObjectName.addActionListener(listener);
Don't forget to make the imports, hope this helps...
I have a Wizard and I need to run a Job in background.
I would like that a Progress Bar shows the fact that job is running, but, at the same time, I don't want that the GUI components of the wizard become disabled.
In other words, I would like to continue to use the wizard while the progress bar is showing the Job in background.
Is it possible?
Thanks to everyone will help me!
You can, you just need to make sure you start a new Job to do the background work, but UI updates still happen in the UI thread:
Job job = new Job("name") {
#Override
protected IStatus run(IProgressMonitor monitor) {
// Do some work
Display.getDefault().asyncExec(new Runnable() {
#Override
public void run() {
// Update UI
}});
return Status.OK_STATUS;
}
};
job.schedule();