popuppanel is called by clickhandler of hyperlink on another popuppanel - java

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();
}
});

Related

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 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.).

Toggle a component's 'enable' property according to a radio button in netbeans

I have two radio buttons in a button group and in the same panel I have a text box and a button. I want to enable the text box and the button only when the second button is selected and be disabled when the other radio button is selected. I've tried this and it didn't work.
private void radio_button2ActionPerformed(java.awt.event.ActionEvent evt) {
if(buttonGroup1.getSelection()==radio_button2)
{
button.setEnabled(true);
textbox.setEnabled(true);
}
Where have I gone wrong?
You don't want to use an ActionListener because the event only fires when you click the button. Instead you can use an ItemListener so an event is generated when the item is selected or deselected (by clicking the other radio button). Something like:
radioButton2.addItemListener( new ItemListener()
{
public void itemStateChanged(ItemEvent e)
{
JRadioButton button = (JRadioButton)e.getSource();
component1.setEnabled( button.isSelected() );
component2.setEnabled( button.isSelected() );
}
});

How do I hide a GWT PopupPanel with a clickhandler?

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()

Refresh ListBox After Button clicked

Basically I have a page with a button and listbox on it. When the button is clicked, I use a ClickHandler to add another item to the listbox. However, the listbox is not refreshed unless I use the browser refresh button. Is there a way to do this programmatically without refreshing the entire Window?
Thank you
The following code works for me without any manual refresh (tested on Firefox 3.6.12 and Safari 5.0.2 with GWT 2.0.3):
public void onModuleLoad() {
final RootPanel rootPanel = RootPanel.get();
final ListBox listBox = new ListBox();
listBox.addItem("Alpha");
rootPanel.add(listBox);
final Button button = new Button("Button");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(final ClickEvent event) {
listBox.addItem("Beta");
}
});
rootPanel.add(button);
}
Please test, if my code works for you, too. Is there something special about your code (or maybe you're using a different browser that behaves differently?)

Categories