ActionEvent not recognizing CTRL keybinding - character

I'm trying to integrate keybindings into a program I'm making, but as that program is long, I'm trying to learn on a smaller similarly coded program that I found on StackOverflow. Here's the code I'm using:
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
public class Demo {
#SuppressWarnings("serial")
private void initGUI() {
JPanel content = new JPanel(new FlowLayout());
content.add(new JLabel("Test:"));
AbstractAction buttonPressed = new AbstractAction() {
#Override
public void actionPerformed(ActionEvent e) {
System.out.println(e.getActionCommand());
System.out.println(e.getSource());
if ("a".equals(e.getActionCommand()))
content.setBackground(new Color(227, 19, 19));
if ("b".equals(e.getActionCommand()))
content.setBackground(new Color(0, 225, 19));
}
};
JButton submit = new JButton("Submit");
submit.addActionListener(buttonPressed);
submit.getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_A,
java.awt.event.InputEvent.CTRL_DOWN_MASK),
"A_pressed");
submit.getActionMap().put("A_pressed", buttonPressed);
submit.getInputMap(javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW).put(
javax.swing.KeyStroke.getKeyStroke(
java.awt.event.KeyEvent.VK_B, 0),
"B_pressed");
submit.getActionMap().put("B_pressed", buttonPressed);
content.add(submit);
JFrame frame = new JFrame("Demo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(content);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
#Override
public void run() {
new Demo().initGUI();
}
});
}
}
What I what to happen is to press CTRL+A and have the background change color. However, when I do this, System.out.println(e.getActionCommand()) is returning a character that looks like a question mark in a box like it's an unknown character or something. The program works if you press B, but adding the modifier CTRL is not working correctly.Is the problem something I'm not doing right? Is the program working correctly and I don't know how to compare e.getActionCommand() and what ever string CTRL+A returns as a ActionEvent? Please help.

in my knowledge if an Action doesn't have its actionCommmand explicitly set it will be set when the ActionEvent is created. in your code the actionCommmand will be the string representation of the charKey of your keyStroke (b and ctrl+a not a)
so i could suggest to put a different action for every action :
class simpleAction extends AbstractAction {
public simpleAction ( String name ) {
super ();
putValue ( Action.ACTION_COMMAND_KEY, name );
}
#Override
public void actionPerformed ( ActionEvent e ) {
System.out.println ( "getActionCommand----->" + e.getActionCommand () );
System.out.println ( "getSource----->" + e.getSource () );
if ( "a".equals ( e.getActionCommand () ) ) {
content.setBackground ( new Color ( 227, 19, 19 ) );
}
if ( "b".equals ( e.getActionCommand () ) ) {
content.setBackground ( new Color ( 0, 225, 19 ) );
}
}
}
JButton submit = new JButton ( "Submit" );
submit.addActionListener ( new simpleAction ( "Submit" ) );
submit.getInputMap ( javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW ).put (
javax.swing.KeyStroke.getKeyStroke ( java.awt.event.KeyEvent.VK_A, java.awt.event.InputEvent.CTRL_DOWN_MASK ), "A_pressed" );
submit.getActionMap ().put ( "A_pressed", new simpleAction ( "a" ) );
submit.getInputMap ( javax.swing.JComponent.WHEN_IN_FOCUSED_WINDOW ).put (
javax.swing.KeyStroke.getKeyStroke (
java.awt.event.KeyEvent.VK_B, 0 ),
"B_pressed" );
submit.getActionMap ().put ( "B_pressed", new simpleAction ( "b" ) );
or a second solution is check the string representation for the ctrl+a
so you change
if ( "a".equals ( e.getActionCommand () ) ) {
content.setBackground ( new Color ( 227, 19, 19 ) );
}
by
if ( "\u0001".equals ( e.getActionCommand () ) ) {
content.setBackground ( new Color ( 227, 19, 19 ) );
}

Related

How to go from one JFrame to another Jframe with a JButton

I have removed all of the code besides the JFrame stuff so it would be easier to see. I want to be able to click a JButton, and that should take me to an existing JFrame in another class. I will provide two classes below. I added the action listener however it does nothing.
package testjframe;
import java.awt.*;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
/**
*
*
*/
public class TestJframe
{
public static void main(String[] args)
{
JFrame P1Frame = new JFrame ( "Project 1" );
P1Frame.pack();
P1Frame.getContentPane().setBackground(Color.BLACK);
P1Frame.setSize(new Dimension(800, 900));
P1Frame.setLayout(null);
P1Frame.setLocationRelativeTo(null);
P1Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
P1Frame.setLayout ( new FlowLayout () );
P1Frame.setVisible ( true );
P1Frame.setResizable(false);
JButton f2 = new JButton("Frame 2");
P1Frame.add(f2);
f2.addActionListener(new ActionListener()
{
#Override
public void actionPerformed(ActionEvent e)
{
new NewForm();
}
});
}
}
package testjframe;
import java.awt.*;
import javax.swing.*;
/**
*
*
*/
class NewForm
{
public static void main(String[] args)
{
JFrame P2Frame = new JFrame ( "Project 1 second Frame" );
P2Frame.pack();
P2Frame.getContentPane().setBackground(Color.RED);
P2Frame.setSize(new Dimension(800, 900));
P2Frame.setLayout(null);
P2Frame.setLocationRelativeTo(null);
P2Frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
P2Frame.setLayout ( new FlowLayout () );
P2Frame.setVisible ( true );
P2Frame.setResizable(false);
}
}

How to draw on jPanel with JOgl

I use JOGL in Netbeans 8.0.2. I want to draw the classic colored triangle on a panel and also to select number of sides of the geometrical figure (4, 5 sides) using the Netbeans palette controls but I have no idea how.The panel is on the frame. So far my code is :
Class PanelGL:
package panelgl;
import com.jogamp.opengl.*;
import com.jogamp.newt.event.WindowAdapter;
import com.jogamp.newt.event.WindowEvent;
import com.jogamp.newt.opengl.GLWindow;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.awt.GLCanvas;
import com.jogamp.opengl.awt.GLJPanel;
import java.awt.Dimension;
import javax.swing.JFrame;
public class PanelGL implements GLEventListener{
public static void main(String[] args) {
final GLProfile profile = GLProfile.get( GLProfile.GL2 );
GLCapabilities capabilities = new GLCapabilities(profile);
final GLJPanel glpanel = new GLJPanel( capabilities );
PanelGL triangle = new PanelGL();
glpanel.addGLEventListener( triangle );
glpanel.setSize( 400, 400 );
final GLFrame frame = new GLFrame ("Colored Triangle");
frame.getContentPane().add( glpanel );
frame.setSize( frame.getContentPane().getPreferredSize());
frame.setVisible( true );
}
#Override
public void init(GLAutoDrawable glad) { }
#Override
public void dispose(GLAutoDrawable glad) { }
#Override
public void display(GLAutoDrawable glad) {
final GL2 gl = glad.getGL().getGL2();
gl.glBegin( GL2.GL_TRIANGLES );
gl.glColor3f( 1.0f, 0.0f, 0.0f ); // Red
gl.glVertex3f( 0.5f,0.7f,0.0f ); // Top
gl.glColor3f( 0.0f,1.0f,0.0f ); // green
gl.glVertex3f( -0.2f,-0.50f,0.0f ); // Bottom Left
gl.glColor3f( 0.0f,0.0f,1.0f ); // blue
gl.glVertex3f( 0.5f,-0.5f,0.0f ); // Bottom Right
gl.glEnd();
}
#Override
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) { }
}
Class GLFrame
public class GLFrame extends javax.swing.JFrame {
public GLFrame(String title) {
this.setTitle(title);
initComponents();
}
private javax.swing.JPanel glPanel;
}
glPanel is add via palette.
I want that the drawing to be on this specifically panel (glPanel).
Create a class that extends GLJPanel instead of GLEventListener. You would still use the GLEventListener internally. After you have compiled the class you can right click it in the Projects window for the pop-up menu to select Tools -> Add To Palette ... to add it to the palette. To Create a property that will be editable just use the normal bean pattern with getter and setter or use Alt-Insert and then select Add Property to add the variable and getter and setter.
eg..
import com.jogamp.opengl.GL2;
import com.jogamp.opengl.GLAutoDrawable;
import com.jogamp.opengl.GLCapabilities;
import com.jogamp.opengl.GLEventListener;
import com.jogamp.opengl.GLProfile;
import com.jogamp.opengl.awt.GLJPanel;
import java.awt.Dimension;
public class MyJOGLFigure extends GLJPanel {
public MyJOGLFigure() {
this.setPreferredSize(new Dimension(100,100));
final GLProfile profile = GLProfile.get(GLProfile.GL2);
GLCapabilities capabilities = new GLCapabilities(profile);
this.addGLEventListener(new GLEventListener() {
#Override
public void init(GLAutoDrawable glad) {
}
#Override
public void dispose(GLAutoDrawable glad) {
}
#Override
public void display(GLAutoDrawable glad) {
System.out.println("numberOfSides = " + numberOfSides);
final GL2 gl = glad.getGL().getGL2();
gl.glBegin(GL2.GL_TRIANGLES);
gl.glColor3f(1.0f, 0.0f, 0.0f); // Red
gl.glVertex3f(0.5f, 0.7f, 0.0f); // Top
gl.glColor3f(0.0f, 1.0f, 0.0f); // green
gl.glVertex3f(-0.2f, -0.50f, 0.0f); // Bottom Left
gl.glColor3f(0.0f, 0.0f, 1.0f); // blue
gl.glVertex3f(0.5f, -0.5f, 0.0f); // Bottom Right
gl.glEnd();
}
#Override
public void reshape(GLAutoDrawable glad, int i, int i1, int i2, int i3) {
}
});
}
// Example editable property.
private int numberOfSides = 3;
/**
* Get the value of numberOfSides
*
* #return the value of numberOfSides
*/
public int getNumberOfSides() {
return numberOfSides;
}
/**
* Set the value of numberOfSides
*
* #param numberOfSides new value of numberOfSides
*/
public void setNumberOfSides(int numberOfSides) {
this.numberOfSides = numberOfSides;
}
}
After you have dragged the MyJoglFigure from the palette to the JFrame design, you can find and edit the numberOfSides property. NOTE that I only print it, i didn't actually use it to change the drawing. ( exercise for the reader ? )

Does the SimpleBeanEditorDriver support autoboxing?

I have a simple bean:
public class SimpleBean implements Serializable {
String stringMe;
double autoboxMe;
// ... boilerplate ...
}
I have created a view implementing Editor.
public class View extends Component implements Editor<SimpleBean> {
#UiField
HasValue<String> stringMeEditor;
#UiField
HasValue<Double> autoboxMeEditor;
// boilerplate uibinder blabla
}
If I run this editor, either standalone or in a tree, I only receive a value for the string in the view, the double-box stays empty.
If I take the burden to write a LeafValueEditor, explicitely setting the values, in the setValue() method, the doubles appear.
So, where is the issue? Is the SimpleBeanEditorDriver not autobox-able and won't find the matching editor field?
UPDATE: The actual code has been asked for.
This is the actual editor. This editor works only, if the LeafValueEditor is in place. If the LVE is replaced by a simple "Editor", it will not present any value.
I know that there will be an issue with NPE if the value is null, but that can be managed with Validation.
package de.srs.pen.portal.widgets.metadataeditor;
import com.google.gwt.activity.shared.Activity;
import com.google.gwt.editor.client.LeafValueEditor;
import com.google.gwt.user.client.ui.IsWidget;
import de.srs.pen.api.meta.xml.PageClip;
import de.srs.pen.portal.widgets.editors.HasDeleteHandlers;
import de.srs.pen.portal.widgets.utils.HasActivity;
public interface PageClipEditor
extends Activity
{
public interface View
extends IsWidget, HasActivity<PageClipEditor>, LeafValueEditor<PageClip>, HasDeleteHandlers
{
void removeFromParent();
}
}
This is the implementation of the View interface.
package de.srs.pen.portal.widgets.metadataeditor;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.event.shared.HandlerRegistration;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.Widget;
import de.srs.pen.api.meta.xml.PageClip;
import de.srs.pen.portal.widgets.editors.EditorDeleteEvent;
import de.srs.pen.portal.widgets.editors.EditorDeleteEventHandler;
public class PageClipEditorView
extends Composite
implements PageClipEditor.View
{
private static PageClipEditorViewUiBinder uiBinder = GWT.create( PageClipEditorViewUiBinder.class );
interface PageClipEditorViewUiBinder
extends UiBinder<Widget, PageClipEditorView>
{}
private PageClipEditor activity;
#UiField
HasClickHandlers btnDelete;
#UiField
#Path("id")
HasValue<String> idEditor;
#UiField
#Path("display")
PageDisplayEnumEditor displayEditor;
#UiField
#Path("xPos")
HasValue<Double> xPosEditor;
#UiField
#Path("yPos")
HasValue<Double> yPosEditor;
#UiField
#Path("height")
HasValue<Double> heightEditor;
#UiField
#Path("width")
HasValue<Double> widthEditor;
public PageClipEditorView() {
initWidget( uiBinder.createAndBindUi( this ) );
}
#Override
public void setActivity(PageClipEditor activity) {
this.activity = activity;
}
#Override
public PageClipEditor getActivity() {
return this.activity;
}
#Override
public HandlerRegistration addDeleteHandler(EditorDeleteEventHandler handler) {
return addHandler( handler, EditorDeleteEvent.TYPE );
}
#UiHandler("btnDelete")
public void handleDelete(ClickEvent ev) {
fireEvent( new EditorDeleteEvent() );
}
#Override
public void setValue(PageClip value) {
displayEditor.asEditor().setValue( value.getDisplay() );
heightEditor.setValue( value.getHeight() );
widthEditor.setValue( value.getWidth() );
xPosEditor.setValue( value.getxPos() );
yPosEditor.setValue( value.getyPos() );
idEditor.setValue( value.getId() );
}
#Override
public PageClip getValue() {
PageClip clip = new PageClip( idEditor.getValue(),
xPosEditor.getValue(), yPosEditor.getValue(),
widthEditor.getValue(), heightEditor.getValue(),
displayEditor.asEditor().getValue() );
return clip;
}
}
This is the uibinder template file.
<!DOCTYPE ui:UiBinder SYSTEM "http://dl.google.com/gwt/DTD/xhtml.ent">
<ui:UiBinder xmlns:ui="urn:ui:com.google.gwt.uibinder"
xmlns:g="urn:import:com.google.gwt.user.client.ui" xmlns:p="urn:import:de.srs.pen.portal.widgets.metadataeditor">
<ui:with type="de.srs.pen.portal.widgets.metadataeditor.MetadataEditorText"
field="res" />
<ui:with type="de.srs.pen.portal.widgets.icons.WidgetIcons"
field="icon" />
<ui:style>
</ui:style>
<g:HTMLPanel>
<g:Image ui:field="btnDelete" resource="{icon.circleCloseDeleteGlyph}"
height="16px" width="16px" title="{res.pageclipDelete}" />
<g:InlineLabel text="{res.pageclipName}" />
<g:TextBox ui:field="idEditor" width="5em"/>
<g:InlineLabel text="{res.pageclipDisplay}" />
<p:PageDisplayEnumEditor ui:field="displayEditor" />
<g:InlineLabel text="{res.pageclipXPos}" />
<g:DoubleBox ui:field="xPosEditor" width="2.5em" />
<g:InlineLabel text="{res.pageclipYPos}" />
<g:DoubleBox ui:field="yPosEditor" width="2.5em" />
<g:InlineLabel text="{res.pageclipHeight}" />
<g:DoubleBox ui:field="heightEditor" width="2.5em" />
<g:InlineLabel text="{res.pageclipWidth}" />
<g:DoubleBox ui:field="widthEditor" width="2.5em" />
</g:HTMLPanel>
</ui:UiBinder>
And finally, this is the PageClip Object itself.
package de.srs.pen.api.meta.xml;
import java.io.Serializable;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlRootElement;
#XmlAccessorType(XmlAccessType.FIELD)
#XmlRootElement(name = "clip", namespace = "urn:srs.pdx.metadata")
public class PageClip implements Serializable {
/**
*
*/
private static final long serialVersionUID = 5556156665068106790L;
#XmlAttribute(required=true)
protected String id;
#XmlAttribute(name = "xPos", required = true)
protected double xPos;
#XmlAttribute(name = "yPos", required = true)
protected double yPos;
#XmlAttribute(name = "width", required = true)
protected double width;
#XmlAttribute(name = "height", required = true)
protected double height;
#XmlAttribute(name ="display", required = false)
protected String display;
public PageClip() {
}
public PageClip( String id, double xPos, double yPos, double width, double height ) {
super();
this.id = id;
this.xPos = xPos;
this.yPos = yPos;
this.width = width;
this.height = height;
}
public PageClip( String id, double xPos, double yPos, double width, double height, String display ) {
this(id, xPos, yPos, width, height);
this.display = display;
}
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public double getxPos() {
return xPos;
}
public void setxPos(double xPos) {
this.xPos = xPos;
}
public double getyPos() {
return yPos;
}
public void setyPos(double yPos) {
this.yPos = yPos;
}
public double getWidth() {
return width;
}
public void setWidth(double width) {
this.width = width;
}
public double getHeight() {
return height;
}
public void setHeight(double height) {
this.height = height;
}
public String getDisplay() {
return display;
}
public void setDisplay(String display) {
this.display = display;
}
#Override
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append( "PageClip [id=" )
.append( id )
.append( ", xPos=" )
.append( xPos )
.append( ", yPos=" )
.append( yPos )
.append( ", width=" )
.append( width )
.append( ", height=" )
.append( height )
.append( ", display=" )
.append( display )
.append( "]" );
return builder.toString();
}
#Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((display == null) ? 0 : display.hashCode());
long temp;
temp = Double.doubleToLongBits( height );
result = prime * result + (int)(temp ^ (temp >>> 32));
result = prime * result + ((id == null) ? 0 : id.hashCode());
temp = Double.doubleToLongBits( width );
result = prime * result + (int)(temp ^ (temp >>> 32));
temp = Double.doubleToLongBits( xPos );
result = prime * result + (int)(temp ^ (temp >>> 32));
temp = Double.doubleToLongBits( yPos );
result = prime * result + (int)(temp ^ (temp >>> 32));
return result;
}
#Override
public boolean equals(Object obj) {
if( this == obj ) {
return true;
}
if( obj == null ) {
return false;
}
if( !(obj instanceof PageClip) ) {
return false;
}
PageClip other = (PageClip)obj;
if( display == null ) {
if( other.display != null ) {
return false;
}
}
else if( !display.equals( other.display ) ) {
return false;
}
if( Double.doubleToLongBits( height ) != Double.doubleToLongBits( other.height ) ) {
return false;
}
if( id == null ) {
if( other.id != null ) {
return false;
}
}
else if( !id.equals( other.id ) ) {
return false;
}
if( Double.doubleToLongBits( width ) != Double.doubleToLongBits( other.width ) ) {
return false;
}
if( Double.doubleToLongBits( xPos ) != Double.doubleToLongBits( other.xPos ) ) {
return false;
}
if( Double.doubleToLongBits( yPos ) != Double.doubleToLongBits( other.yPos ) ) {
return false;
}
return true;
}
}
Yes, autoboxing is supported, though you should be very careful that it is actually what you want - if the autoBoxMeEditor.getValue() returns null, there will be a NullPointerException when you call driver.flush().
With that said, HasValue is not an editor, and your 'bean' has no getters and setters - these two facts should mean that none of your editor should work, instead of only the string. If you update the question with the real code, I will check back later.
From your edit:
This is the actual editor. This editor works only, if the LeafValueEditor is in place. If the LVE is replaced by a simple "Editor", it will not present any value.
This is the problem, and this is why it appears to work without actually saying that your subeditors are Editors:
#Override
public void setValue(PageClip value) {
displayEditor.asEditor().setValue( value.getDisplay() );
heightEditor.setValue( value.getHeight() );
widthEditor.setValue( value.getWidth() );
xPosEditor.setValue( value.getxPos() );
yPosEditor.setValue( value.getyPos() );
idEditor.setValue( value.getId() );
}
You should not have to write that method, but since a) you are not referring to your editors as Editors, and b) you are making the parent a LeafValueEditor, you must.
First, what does LeafValueEditor mean? In short, your type is saying "I represent some leaf in the editing tree - do not bother to look at my children (i.e. fields) to figure out how to bind sub-editors'. If you had instead actually implemented Editor<PageClip>, the editor system would have looked at the class, and tried to find any editor fields.
Next, since you don't have any editor fields, moving to Editor doesn't help! Instead of referring to your fields as HasValue, refer to them by their real type. This includes the interface LeafValueEditor (remember this from above?), so the String and the double will be bound correctly.
One possible future issue you are going to hit, since you didn't share the code of the driver setup: Make certain that you reference the editor implementation in the driver declaration, not the view interface. You must do this so that the driver knows which impl it is talking to, and what sub-fields (and such, sub-editors) it is expected to have.

Problems with QTest::mouseClick on QListWidget

I am trying to use QTest to do some testing. I have a QListWidget that I would like to click on to get a selection. But after the click, nothing is selected. Does anyone have any ideas?
Here is my test class
void TestGui::List() {
TestDialog dlg;
dlg.show ();
// Click on the centre of the second object
QListWidget *list = dlg.ListWidget ();
QListWidgetItem *item = list->item ( 1 );
QRect rect = list->visualItemRect ( item );
QTest::mouseClick ( list, Qt::LeftButton, 0, rect.center() );
// Check if something was selected
QCOMPARE ( list->currentRow (), 1 );
QVERIFY ( list->currentItem () != NULL );
QCOMPARE ( list->currentItem ()->text (), QString ( "Two" ) );
}
Below is the testing class
class TestGui: public QObject {
Q_OBJECT
private slots:
void List();
};
And here is the TestDialog class used to display the problem
class TestDialog : public QDialog {
Q_OBJECT
public:
TestDialog ( QWidget *parent = NULL )
: QDialog ( parent, Qt::CustomizeWindowHint | Qt::WindowCloseButtonHint ) {
QVBoxLayout *layout = new QVBoxLayout ( this );
m_list = new QListWidget ( this );
m_list->addItem ( "One" );
m_list->addItem ( "Two" );
m_list->addItem ( "Three" );
m_list->addItem ( "Four" );
layout->addWidget ( m_list );
QPushButton *close_button = new QPushButton( "Close" );
connect ( close_button, SIGNAL ( clicked () ), this, SLOT ( close () ) );
layout->addWidget ( close_button );
setWindowTitle( "Test" );
}
QListWidget *ListWidget ( void ) {
return m_list;
};
private:
QListWidget *m_list;
}; // TestDialog
After some more thought, it turns out that the click needs to be on the view widget and not the list itself. So the line should look like this
QTest::mouseClick ( list->viewport (), Qt::LeftButton, 0, rect.center() );
Thanks

actionlistener returning a nullexception on jbutton

I have an action listener set up on my main jframe menu for the buttons listed on it, and they work fine, bringing up other jframes as needed. The problem is when a person clicks the buttons on the jframes brought up I get a nullexception after a jbutton is clicked on that submenu jframe.
Example code:
public class main extends JFrame implements ActionListener
{
public main
{
private JButton thisButton = new JButton( "this" );
private JButton thatButton = new JButton( "that" );
thisButton.addActionListener( this );
thatButton.addActionListener( this );
thisButton.setActionCommand( "THISBUTTON" );
thatButton.setActionCommand( "THATBUTTON" );
setLayOut( new FlowLayout() );
add(thisButton);
public void actionPerformed( ActionEvent event )
{
String source = event.getActionCommand();
if( source.equals( "THISBUTTON" )
{
JFrame thisFrame = new JFrame();
thisFrame.add( thatButton );
if( source.equals( "THATBUTTON" )
{
System.out.println( "pushed thatbutton" );
}
}
}
}
}
Now I am almost certain that I need to set up another action listener for the inner jbutton but I am at a lost to how to do that.
To set up another action listener for the inner JButtons just write this code for each button
thisButton.addActionListener(this);