How do I hide a GWT PopupPanel with a clickhandler? - java

I am trying to make the submit button on my PopupPanel hide the panel, but I cannot seem to get it to function properly. I am able to have a button on my entrypoint show the panel, but I cannot seem to get the PopupPanel to hide.
submitLinkPopup.btnSubmitLink.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
if(if conditions go here){
CallbackMethods.addLink(callback conditions go here);
//this is where I want to hide the panel
}
else{
Window.alert("Error: Fields cannot be empty");
}
}
});

popPanel.hide()

Related

popuppanel is called by clickhandler of hyperlink on another popuppanel

I have 2 gwt PopupPanel in one class. The second popup is expected to be shown when the user clicks the hyperlink on popuppanel1. How can I fix this problem? Thanks
Problem:
Click the hyperlink on popuppanel1
- the popuppanel2 is not shown at all.
PopupPanel popuppanel1=new PopupPanel();
PopupPanel popuppanel2=new PopupPanel();
//popuppanel1 and popuppanel2 add their components
popuppanel1.getHyperlink().addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
popuppanel2.center();
}
});

How to launch a second JFrame from clicking a JButton?

I'm making a To-Do List application and I have a PrimaryList frame and a SubList frame. When a user selects something from the PrimaryList (Grocery...or something like that) and then hits a forward arrow JButton, it is supposed to launch up the SubList frame. Now here is what I have for the actionPerformed method of the forward arrow button called btnArrow.
private void btnArrowActionPerformed(java.awt.event.ActionEvent evt) {
lstToDoLists.addListSelectionListener(new ListSelectionListener(){
public void valueChanged(ListSelectionEvent e){
if (lstToDoLists.getSelectedIndex() > 0){
btnArrow.addActionListener(new ActionListener(){
public void actionPerformed (ActionEvent ae){
if (btnArrow==ae.getSource()){
SubList sublist = new SubList();
sublist.setVisible(true);
}
}
});
}
}
});
}
Now, when I run the PrimaryList file and click on an item in my JList and then select the forward arrow button, I get nothing. But then when I click another element from the list and press the forward arrow button again, my SubList pops up twice.
Something isn't write with what I've written and I am hoping someone else will know how to fix this problem.
You're adding listeners inside of listeners -- something that you don't want to do, since this means that new listeners will be added, each time an event occurs.
Solution: don't add listeners inside of other event listeners but rather add the listeners once and in your code's constructor or initialization method.
Note that I would not use a ListSelectionListener at all. Instead I'd just use a single ActionListener on the button. Then in that listener, get the list's selection and use it.
e.g.,
private void btnArrowActionPerformed(java.awt.event.ActionEvent evt) {
// if list contains String:
String selectedItem = (String) lstToDoLists.getSelectedItem();
// check that selectedItem isn't null, i.e,
if (selectedItem != null) {
// TODO: do something with selection here
}
}
As a side recommendation, please look at The Use of Multiple JFrames, Good/Bad Practice?.

java: jTabbedPane tab clicked event

mainPane.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
mainPaneMouseClicked(evt);
}
});
private void mainPaneMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("hahahahahahhaha");
}
The code above triggers when I click anywhere in the panel, not just the tab.
How do I change it to just fire when the tab is clicked
Also, will I be overriding anything JTabbedPane is doing when a tab is clicked?
You Could...
Use a ChangeListener to detect when the tab selection changes and use something like getSelectedIndex to determine which tab has been selected
You Could...
Instead of moving the JTable from one tab to another, create an instance of a JTable for each tab and share the TableModel between them

How to restart a Java Application launching a specific class of my application?

I have the following situatation:
I have a Java Swing application.
In the class that implement my GUI I have a button named Log Out tath is binding to an event listener that handle the click event, something like it:
JButton logOutButton = new JButton("LogOut");
header.add(logOutButton);
Then in the same class that implement my GUI I have declared the ActionListener that handle this event using an inner class:
logOutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("logOutButton clicked !!!");
System.exit(0);
}
});
In this moment when I click the logOutButton button the program end. I would that instead exit it is restarted by running a specific class called LoginForm (the class that implement the login form GUI)
What can I do to do this thing?
Tnx
Andrea
You don't really need to close/open window junky approach at all. Just use Card Layout:
set Frame's content pane's layout to card layout.
getContentPane().setLayout(new CardLayout());
Put your different Form's content code inside different panel and
add them to the content pane with their corresponding name, for example:
getContetnPane().add(logInFormPanel, "logIn Form");
Now you can simulate the card to appear whenever necessary by calling CardLayout.show(Container parent, String name). For example:
logOutButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent event) {
System.out.println("logOutButton clicked !!!");
CardLayout cl = (CardLayout)(getContentPane().getLayout());
cl.show(getContentPane(), "logIn Form");
}
});
Check out a CardLayout demo from my another answer.

How action a button to open a new pane in java for a GUI

I am creating a GUI in which my home page has a button labelled "Welcome to the Panel"
The point is that when you press on this button, it will navigate to a new page where I will have other functions. My only problem is that I dont know the syntax or how that when clicking a button, it will navigate to new page.
JButton btn = new JButton("Welcome to the Panel");
btn.setActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent e)
{
// Here you open the other window. You can use JFrame, JOptionPane or JDialog
}
});
button.addActionListener(new ActionListner()
{
public void actionPerformed(ActionEvent ae)
{
//code to show pane
}
});
You need to register an ActionListener on your button and inside that action listener you make that panel (the page) visible.
How you do that depends on your layout, i.e. with a CardLayout you'd show the corresponding card (here's the doc). Using other layouts you might have to replace a component, e.g. if you use a BorderLayout and your content is placed in the center, replace the center component with the panel you want to show.
Note that if you're not familiar with layout managers yet, you should first have a look at those before doing dynamic changes to the ui (like navigation etc.).

Categories