Swing/AWT/SWT :: Key Listener On Jbutton

May 25, 2014

I have a Jbutton in my application named as SUBMIT,on clicking SUBMIT the text of jButton changes to ABORT. I wish to apply enter key listener on both the SUBMIT and ABORT button in my applcation, however I am not able to get the text of the button in key listener,so that i can apply my code based on the current text of Button.

View Replies


ADVERTISEMENT

AWT Action Listener In Swing GUI?

Feb 22, 2014

I'm using Eclipse with the Window Builder Pro plugin to create a Java program. I noticed that when I had Eclipse create an action listener for a combobox in a Swing GUI it created an AWT listener.

Did I choose the wrong type of listener? I want my code to use the Swing components because I understand that they are more portable.

View Replies View Related

Swing/AWT/SWT :: Implementing Listener Of GUI In A Different Class?

Jun 26, 2014

I have two different classes called Login (in the package View) and RegButtonListener (in the package Controller). I want to use the MVC pattern.

Login creates a GUI for login. I used NetBeans GUI Builder to create it.

In the class RegButtonListener there is the code for the click of the buttons, then various listeners of the GUI.

Now I want to close the login frame at the click of a button so I want to use the dispose() method.

If I had all the code (GUI code and code of the listener) in the same file, close the frame would be easy enough to do because this.dispose(). But in my case I have two different classes.

I also have a second problem.

In Login class (in the packege View) I have included the line :

regButton.addActionListener(Controller.RegButtonListener).

However, Netbeans tells me an error "package regButton does not exist. <identifier> expected". Why does he consider regButton a package? How can I fix these two problems?

How do I do then?
 
Below is the code of the two classes.

Login class.
public class Login extends javax.swing.JFrame {
/** Creates new form Login */
public Login() {
initComponents();

[code]....

View Replies View Related

Swing/AWT/SWT :: Double Listener With Inner Classes

Feb 19, 2014

In the book we made a GUI which has 2 buttons, a label and a panel (the panel is a subclass of JPanel). What the program does is the following: When I press one of the two buttons, in the panel there is a rectangle that changes its color. When I press the other button it has to change the text on the label. Now the problem is that when I start the program, the FIRST time I press the button on which the label must change, this also changes the color in the rectangle, which it should not (I also noticed that when i FIRST click the rectangle shifts a little bit to the left). After that the program works fine.

Here is my code:

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class TwoButtons{
JFrame fr;
JButton labelButton;
JButton colorButton;
JLabel label;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: JComboBox Listener - Bound Action?

Jul 14, 2014

I have three JComboBoxes. When the user selects an entry in the first JComboBox the entries in the second are set. For this I use an Action extends AbstractAction which is bound to the first JComboBox.

I have also bound an Action to the second JComboBox.

Problem: this also fires when the entries on the second JCombox are added which leads to a Nullpointer.

I need a Listener which only reacts to user input, and does not react when the model of the JComboBox is changed.

View Replies View Related

Swing/AWT/SWT :: How To Pass On Object To Event Listener

Sep 22, 2014

I’m teaching myself Java. I am a fairly proficient programmer in other languages, but this is the first OO language I’m doing.I have a question that is a bit hard to summarize. Or it should be: how can I pass on an object (or variable) to an event listener?

I am writing an application in which you can play a Sudoku game. I have separated the “logic” or the “model”(the classes with Sudoku data structures and methods to manipulate them) from the presentation (the view and the controller).The main method starts off as follows:

SudokuModel model = new SudokuModel();
SudokuView viewController = new SudokuViewController(model);

The first line creates class for the logic and the second line creates the class for the view and the controller. Since the view and the controller need access to the business logic, the model is passed on to the ViewController class.The SudokuViewController class creates the user interface in Swing and it handles the user input. For the user input I have created a number of listeners, like this:

table.addKeyListener(this);

Now these listeners need access to the model since they update it. However, as far as I’m aware the only parameter passed on to an event listener is the event itself. So these event listeners do not have direct access to the model, even though it is passed on to the constructor of the class SudokuViewController.

To circumvent this, I made model2 an attribute (variable) of the class SudokuViewController. The constructor of the class sets this variable as follows:

model2 = model;

Now the event listeners have access to model2, which they can manipulate.This works. However, I think it is an ugly solution, introducing an additional object (model2). I’d like to pass on the object named model to the event listener, but this doesn’t seem to be possible.

View Replies View Related

Swing/AWT/SWT :: Instantiation Of Listener Using Anonymous Inner Class

Jun 2, 2014

JMenuItem blueChoice = new JMenuItem("Blue");
blueChoice.addActionListener(new InnerMenuListener(){
public void actionPerformed(ActionEvent e){
String buttonCommandString = e.getActionCommand( );
if (buttonCommandString.equals("Red"))
redPanel.setBackground(Color.RED);
else if (buttonCommandString.equals("White"))
whitePanel.setBackground(Color.WHITE);
else if (buttonCommandString.equals("Blue"))
bluePanel.setBackground(Color.BLUE);
else
System.out.println("Unexpected error.");
}
});

Can a method in an anonymous inner class ever be private? why or why not?

View Replies View Related

Swing/AWT/SWT :: Action Listener Does Not Work With Button Click

Feb 22, 2015

I have buttons created on a frame and then I register the listener from a controller in a controller-view relationship.

When I click the button on the face, the action never executes for some reason. I thought maybe there was a problem registering the listener but I can call the buttons doclick() method and it executes as it should. Perhaps I'm overlooking something really obvious here but I can't see it.

btnEight = new JButton( "8" );
// btnEight.addActionListener( controller );
btnEight.setBounds( 212, 90, 41, 23 );
frame.getContentPane().add( btnEight );

and then I add the listener

public void setController( ActionListener theController ) {
Component[] components = frame.getContentPane().getComponents();
for ( Component component : components ) {
if ( component instanceof JButton ) {
JButton button = ( JButton ) component;
button.addActionListener( theController );
}
}

again, when i click the button nothing happens. but if i add the following code

btnEight.doclick()

the actionPerformed invokes in theController as I intended.

You can see the entire project on GitHub so you can see the full context. The controller class contains the listener and the view class contains the buttons.

View Replies View Related

Swing/AWT/SWT :: Adding Items To JComboBox Taken From JTextField Listener

Nov 11, 2014

I need to take the value of what's typed in my JTextField, and once the submit button is clicked, I want to add that string to my JComboBox list items.

Depending which RadioButton they selected, I need to put the team in HOME or AWAY teams, and so on and so on, until they continue clicking submit.

View Replies View Related

Swing/AWT/SWT :: JSpinner - Adding Listener To Arrow Buttons

Jan 25, 2007

I need to change the value only when I press one of the arrows in a JSpinner component.How can I add a listener to the arrow buttons. I tried ChangeListener but it was not what I needed

View Replies View Related

JavaFX 2.0 :: TreeView - Swing Tree Will Expand Listener?

Jun 3, 2014

Is there some equivalent of the Swing TreeWillExpand-listener for TreeView?
 
In my particular case I want to check whether some constrains are set to show some children before they will populated in the view.

View Replies View Related

Swing/AWT/SWT :: Listener Called Multiple Times On Single Click?

Jan 30, 2015

I have the following listener on a tableset of names:

ListSelectionListener singleListener=new ListSelectionListener() {
public void valueChanged(ListSelectionEvent e) {
int row=e.getFirstIndex();
if (row==previousRow) {
row=-1;

[Code] .....

The println shows that getValueIsAdjusting is called 4 times when I click a single selection from the list. Is this normal behavior? If so how do I determine which call to really use. If not, where can I look to see why it is being called 4 times on a single click?

View Replies View Related

Swing/AWT/SWT :: Possible To Stop And Start A Listener Alternatively In Java Frames?

Dec 3, 2014

I was developed a simple GUI, in that it requires modification of jtextfield content while JComboBox item selected and vice-versa. I was used itemListener on JComboBox and Document Listener on JTextField. It was gives exception while running the code. Because one listener source effected by another one..

Exceptions are like this:

Exception in thread "AWT-EventQueue-0" java.lang.IllegalStateException: Attempt to mutate in notification
at javax.swing.text.AbstractDocument.writeLock(Unknown Source)
at javax.swing.text.AbstractDocument.replace(Unknown Source)
at javax.swing.text.JTextComponent.setText(Unknown Source)
at ronanki.swing.pcahostsimUI$5.itemStateChanged(pcahostsimUI.java:368)
at javax.swing.JComboBox.fireItemStateChanged(Unknown Source)

[Code] ......

View Replies View Related

Swing/AWT/SWT :: JButton Does Not Do All Tasks

Aug 3, 2014

I have a jButton that when the action perform runs it only does part of the tasks some of the code doe not appear to run and i just can not figure out why i have tried wrapping parts of it in an if statement and it still do not run so here is the code behind the button:

in the code the parts that do not run are jTextField10.setText("Working Please Wait"); and jButton15.setVisible(false);

what i am expecting to happen is the text field has the words Working Please Wait placed in it , this does not happen and the button should be hidden to prevent it being clicked a second time again this does not happen

the rest of the code works as expected

InputStream inStream;
OutputStream outStream;
try {
File afile = new File("C://templates//amendments.xls");
File bfile = new File("C://amendments.xls");
inStream = new FileInputStream(afile);
outStream = new FileOutputStream(bfile);

[code]....

View Replies View Related

Swing/AWT/SWT :: How To Show A JButton

Sep 25, 2014

I'm not sure what I'm doing wrong but none of the buttons will show below. I tried using .add with the container name but it kept giving me an error. When I just put add.(); it seems fine but then nothing shows. Is there something I'm missing that's required?

import java.awt.Container;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
@SuppressWarnings("serial")

[code]....

View Replies View Related

Swing/AWT/SWT :: JButton Actionlistener Not Working?

Mar 5, 2014

I was suspecting I had a jButton not working, so I added a console print to test. See below. When I click the button, the console doesn't display anything. Am I using the button wrong?

private void jButtonUpdateItemsMouseClicked(java.awt.event.MouseEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}

I have also tried the following with the same results (or lack of).

private void jButtonUpdateMajorDeckItemsActionPerformed(java.awt.event.ActionEvent evt) {
System.out.println("click");
System.out.println(drawPreviousRectangle);//this is a boolean
}

View Replies View Related

Swing/AWT/SWT :: Setting Icon On JButton

Feb 23, 2014

Recently I have been working on an executable launcher. I tried to get the executable icons and set them on the JButtons. Still there are some problems. Here is a part of the code:

try {
button[i].setIcon(FileSystemView.getFileSystemView().getSystemIcon(new File(getConfig("path." + (i+1)))));
}
catch (NullPointerException ex) {
}

Here the getConfig() method is already defined to get a string in a "properties" file. However, the icons are very small and they don't fill the entire button.

How can the icon fill the entire button (for example, having a custom size of 48x48, or automatically filled the button)? The frame will not be resized.

Here is the whole code...

import java.awt.*;
import java.awt.event.*;
import java.awt.image.*;
import java.io.*;
import java.io.File.*;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change Jbutton Color While It Is In Focus

Jan 27, 2013

refer to this code~

import java.awt.GridLayout;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.Color;
import javax.swing.JButton;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Change Action After 1st JButton Click

Aug 3, 2014

I am relatively new to java. . I cannot...(actually do not know) how to change the actionlistener (actionPerformed) after the second click in an array of JButtons. This is how the program performs right now.

On the 1st click on the grid, the border of the button clicked will change to 'blue' and another button will change its boarder to 'red'. on the next click the same action is performed.

What I need is to change action when the 'red' bordered button is clicked, lets say change the color of the buttons from the 'red' to the 'blue' buttons.(x 3 buttons).

The logic about how to perform the final result I think I can do on my own but my problem is how to change the action when the red bordered button is clicked.

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.BorderFactory;

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Need To Draw JButton Such That It Displays On Top Of Two Different Panels

Mar 3, 2015

one of the java swing challenge I am facing. Problem statement: there are two JPanels panel 1 and panel 2 placed on a JFrame one below the other as panel 2 below panel 1. Now, I need to put a JButton in any one of the panels such that this JButton displays half in panel 1 and half in panel 2.

View Replies View Related

Swing/AWT/SWT :: How To Enlarge The Clickable Area Of A JButton

Jan 30, 2015

what I have already tried:

to set the margin of a button - didn´t work
to set anything like padding - didn´t found something for java
to set an empty border - didn´t work

I don´t know what to try next.

My main problem is to enlarge the clickable area without resizing the buttons image.

View Replies View Related

Swing/AWT/SWT :: JButton Opening New JFrame In New Window

Oct 14, 2014

We are creating a quiz as a school program, we are using netbeans and we have a little problem. The problem is that our JButton opens a new JFrame in a new window and we want it to stay in the same window. The code we are using is:

private void PlayButtonActionPerformed(java.awt.event.ActionEve nt evt) {
Question1 s = new Question1 ();
s.setVisible(true);
}

Is it possible to make it stay in the same window?

View Replies View Related

Swing/AWT/SWT :: Execute Main Class Into A JButton?

Mar 10, 2014

how can i execute the main class into a JButton.

Example: Main Class

public class ComparativoV3{
public void loadComparative(String path){
}
public void compareDbs(){

[Code].....

how to set it up the private void CompareActionPerformed(java.awt.event.ActionEvent evt) as the ComparativeV3 main class, not giving it any argument, because the files are load from the arguments section & it reads diferent files with diferent arguments.

View Replies View Related

Swing/AWT/SWT :: How To Update / Refresh JPanel On JButton Click

Apr 14, 2015

I am trying to plot a graph and graph should display when JButton is clicked. To create data set, I am taking some value through JTextField and then created a chart and plotted it. I've got a problems: the chart doesn't refresh/update when I change the text field value.

public class Test2 extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
private JPanel contentPane;
private ChartPanel chartPanel;
private JTextField textField_1;
double a;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: How To Put A JButton At Lower Right Corner Of JDialog With MigLayout

Jan 26, 2014

With the MigLayout for Swing, I'd like to see the JDialog looking like the standard windows Dialog,where to have the OK and cancel buttons at the lower right corner.

View Replies View Related

Swing/AWT/SWT :: How To Change JLable Text By Pressing JButton

Feb 25, 2015

i just started java and I'm trying to change the JLabel text by clicking on the JButton however it isn't working,

import java.awt.BorderLayout;
import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JLabel;
public class BorderLayoutJFrame extends JFrame
{
public static final int WIDTH = 400;
public static final int HEIGHT = 400;

[Code]...

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved