Swing/AWT/SWT :: JButtons Disappearing On Click And Reappearing When Mouseover Occurs

Mar 30, 2015

I'm having issues with JButtons and painting methods, whenever I click a grid on the board, the buttons in the JPanel disappear. Here is the board class:

package GUI;
public class Board extends JPanel implements Observer {
/**
*
*/
// private static final long serialVersionUID = 1L;
private final int boardSizeX;
private final int boardSizeY;
private final int L = 20;

[Code] ....

I know the code is messy in places, this will be fixed later, just need some pointers on how to solve the JButton issue.

View Replies


ADVERTISEMENT

Swing/AWT/SWT :: Buttons Not Displaying Till Mouseover Them?

Jan 19, 2012

I set out to make a Tic-tac-toe (Cross and Noughts) game to test my learning so far. While things have gone pretty well so far, I am absolutely stumped by my current issue. When I compile and run the code, the Grid of buttons that I generate do not appear. However, if I mouse over the window, they seem to then get refreshed/repainted. I cannot for the life of me figure out why this is happening. From Googling the issue, it seems this is either an issue with the layout manager or related to a thread conflict with the GUI? [URL] ....

I'm listing out the code for the game class and the button class.

import java.awt.event.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class CrossNoughtsGame {
private JFrame frame;
private JPanel mainPanel;
private ArrayList<CNButton> buttonList = new ArrayList<CNButton>();
private boolean isX = true;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: ActionCommand With JButtons

Jun 14, 2014

I have a simple program and i want to use ActionCommand with my JButtons to print text. This is the code i have so far, why this isn't working?

import java.awt.EventQueue;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.EmptyBorder;

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Adding ActionListeners To JButtons

Mar 11, 2009

I have an application that reads through a ResultSet... while I'm reading that ResultSet, I am creating new JButtons..... Now I need to add an ActionListener to those JButtons...... but they are not visible to the actionPerformed method. So I thought I'd try to add an ActionListener as I created the buttons with the following code:

final File file = new File(rs.getString(3));
SKPictureButton spb = new SKPictureButton(url,file.getName());
spb.addActionListener (
new ActionListener() {
public void actionPerformed( ActionEvent e )

[Code] ....

However this seems a bit excessive to me..... I don't think I really want to be creating a new ActionListener class for each JButton do I ? Is there a better way to make the JButtons created in this method visible to the actionPerformed method ? I'm just gettin' back into the "Swing" of things in Java.... haven't coded it for a while.

View Replies View Related

Swing/AWT/SWT :: How To Run Other Java Program With Jbuttons

Mar 16, 2014

i have 2 java program the first java program is main menu of my program. the 2nd is Calculator.

#1 Program: Main Menu

import java.awt.event.ActionListener;
import java.awt.event.*;
import java.awt.*;

[Code].....

in the main menu there is a Jbuttons. is there a way to run the #2 program: Calculator when the 1st Jbutton(Calculator button) clicked ?

View Replies View Related

Swing/AWT/SWT :: Adding ActionListener To 9 JButtons

Mar 8, 2014

I need to add actionlistener to my code which allow the number 1 to 9 to function which are located in the nested for loop.

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class EX_7_2 extends JFrame {
public EX_7_2() {
setLayout(new BorderLayout(5, 10));

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Getting JButtons To Display Text?

Sep 25, 2014

I am in the middle of creating a chess application, and am currently working on laying out a list of moves on the right of the actual board. Specifically, I want to have a JLabel that says "moves" on top of a JList that contains the moves, on top of two buttons, labeled "<" and ">" respectively, to which I will eventually add functionality to take back and un-take back moves. Currently I have the first two parts down, but when I add my buttons,the other components are getting messed up.

I have all of these things in a vertical BoxLayout inside of a JPanel with a fixed width of 70, and a height that varies according to the size of the window (I overrode the getPreferredSize method of the JPanel). The two buttons are within their own JPanel with a grid layout with one row and two columns. Then I basically just add the moves list label, the movesList, and the panel housing the buttons to the larger panel, in that order.

However, I am encountering two problems. One, the buttons display the text "... " instead of "<" and ">" as if there is not enough room, although I'm pretty sure three periods take up more space than one less than or more than sign. The next is that, without the buttons at the bottom, the label reading "moves" is appropriately centered (or left aligned, I can't tell which) over the movesList, and you can read its whole text. However, when I add in the buttons at the bottom, the label of the top shifts over to the right and then reads "mov..." because it has run out of room.

Here is my code:

//move list
movesListLabel = new JLabel("Moves");
//the components for the actual movesList come from another class with an object called pen, but I don't think this is the problem
listModel = pen.getListModel();
JList movesList = pen.getMovesList();
JScrollPane listScroller = pen.getMovesListScrollPane();

[Code] .....

View Replies View Related

Swing/AWT/SWT :: Resizing Images In Jbuttons In Grid Layout

Jun 21, 2014

Am trying to dynamically insert buttons (which will be presenting card in a frame) using grid layout.As shown image is getting inserted but its not fit in button.I tried Darryl's Stretch icon as well but of no support.

panel_playerCards.setLayout(new GridLayout(2,10, 0, 0));
for(int i=0;i<9;i++){
StretchIcon icon=new StretchIcon(UnoGui.class.getResource("/UnoColors/green/card10.png"));
btnArr[i].setIcon(icon);
btnArr[i].addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
}
});

View Replies View Related

Bouncing Ball Around The Screen - It Keeps Disappearing

Oct 23, 2014

I'm trying to do is get this ball to bounce around the screen and ive gotten so far but not sure how to proceed. The ball keeps disappearing.

//bouncing ball

float x; //ball x position
float dx = 3; //ball x direction is right, step 5
float y; //ball y position
float dy = 3;
void setup () //runs once at start

[Code] ....

View Replies View Related

Add A Background Image For Code Without Disappearing Button And Label?

Mar 10, 2014

How can i add a background image for this code without disappearing the button and label? I want a frame that has a background and still shows the buttons and label that I place. and how can I insert Buffered Reader in this code, this is a file organizer, but it only shows first line of a text file. I want to show the whole text file. And is it possible to also show path of the file?

import javax.swing.JFrame;
import javax.swing.JButton;
import javax.swing.JTextField;
import java.awt.Color;
import java.awt.Container;
import java.awt.FlowLayout;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Scanner;

[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 :: 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 :: Unable To Show Image When Click On Button

Oct 21, 2014

I've recently decided to learn Java on my own using internet material such as forums, blogs and you tube. Ive never programed before but through some research I concluded that Java is going to be on the mid spectrum of difficulty as far as verbiage goes. I ma in no way implying that Java is easy but instead closer to spoken English that c++ if my research is correct. So here is my attempt at a basic program where I click a button and it will make an image appear. Not sure where Im falling short

package clicktoimage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Clicktoimage extends JFrame {
private JLabel label;
private ImageIcon image;

[Code]...

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 :: Running Exe On Click Of Button Packaged As Resource In Jar

Mar 17, 2015

So this is my package structure:

Projectsrccom.mypackageMyClass.java
resourcesicon.pngmyexe.exe
Right now I have to run the exe like this : - It has hardcoded the path of the exe :command = "cmd /c start /b cmd.exe /K "cd " + outputFolderPath
+ " && C:myfoldermyexe.exe " + "param1=value1 param2=value2 " ;

Process p = Runtime.getRuntime().exec(command); This works fine. But, When I package it as a jar I want to give a relative path to my resources folder. How can I make this happen?

I tried:File f = new File("resources/myexe.exe");
String path = f.getAbsolutePath();
but this "path" did not work.

Another way would be to extract the exe to a local path on the server, but there is a possibility that I could face permission issues.

View Replies View Related

Swing/AWT/SWT :: CardLayout Switching Panels On Click Of Button

Jun 19, 2014

I am trying to switch panel on click of a button but nothing is happening.

package game.uno.swings;
import java.awt.EventQueue;
import javax.swing.JFrame;
import java.awt.CardLayout;
import javax.swing.JPanel;

[Code] ....

I read the oracle doc example, i understand the concept but still nothing is happening on show,first ,next method of CardLayout in ActionPerformed. Code is highlighted where I am facing problem.

View Replies View Related

Swing/AWT/SWT :: Add Buttons Dynamically In A New Jpanel On Click Of A Button

Jun 20, 2014

Am trying to add buttons dynamically in a new Jpanel on click of a button. i am getting new Jpanel but not able to see the buttons.

btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
//unoGameController.playGame(playerFirst.getText(), playerSecond.getText());
CardLayout cardLayout=(CardLayout)(frmUno.getContentPane().getLayout());

[Code]...

prepareHandsForGuiCode is

public UNODeckMain prepareHandsForGui(UNODeckMain unoDeckMain){
JButton[] btnArr =new JButton[50];
for(int i=0;i<50;i++){
btnArr[i]=new JButton("hi");
panel_player1.add(btnArr[i]);
}return unoDeckMain; }

Am i skipping something ?

View Replies View Related

Swing/AWT/SWT :: Changing Panel In Jframe On Click Of A Button

Jun 22, 2014

I want to switch panel on click of a button and code for switching panels is written in update method (Which gets called from notify observer of another class as part of Observer pattern.

unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

playGame in Panel 1 of class 1 calls another class (class 2)and data comes in update method of class 1(Observer interface).

Now for switching panels code is in gameControllerDataProcessing . I am not able to switch the panels when this functionality runs.

However if i dont call the unoGameController.playGame(playerFirst.getText(), playerSecond.getText() and directly call the update method or directly write the switching panel code . then it works fine.

btnNewButton_1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if((!(playerFirst.getText().equalsIgnoreCase("") ||playerSecond.getText().equalsIgnoreCase(""))&&(!playerFirst.getText().equalsIgnoreCase(playerSecond.getText())) ) ){
unoGameController.playGame(playerFirst.getText(), playerSecond.getText());

[Code] .....

View Replies View Related

Swing/AWT/SWT :: JTable Using CTRL / Click For Multiple Row Selection

Jul 6, 2014

I know how to do single selection, but I would like to do multiple row selection only by using CTRL + click without the option of dragging the mouse to select rows. So the user would have to hit ctrl + click each time to highlight additional rows.

View Replies View Related

Swing/AWT/SWT :: Wait For Mouse Click Before Running While Loop

Oct 7, 2013

I've got the game working just fine, but I don't like the way it starts playing the second you hit the "Run Last Class" button in Eclipse, and would really like to have the game start, then wait for the user to click a button before running the core WHILE loop. Everything is implemented in a single class, and here is the playGame method that starts the ball moving:

private void playGame(){
while (!gameover){
moveBall();
checkForCollisions();
}

All I want to do is pause before the WHILE loop until the users clicks the mouse button, nothing fancier than that! I've done quite a bit of reading, and it looks like ActionEvent may be the way to go, but I'm not clear on how to use it correctly in this scenario.

View Replies View Related

Swing/AWT/SWT :: Table With JCheckBox - Fire Event On Click

Feb 10, 2015

I would like to get a checkbox within a table to fire an event when it's clicked rather. I gave tried putting in a TableModelListener but the the event only seems to trigger when I click on another column (as if the table is waiting to see if I will change my mind) before moving on.

I have also looked at the setValue of the TableModel itself.

Do I need to put an ActionListener on each checkbox or have I missed something ?

View Replies View Related

Swing/AWT/SWT :: Detecting Mouse Click Inside A Box Painted In Frame?

Feb 9, 2015

In the method mouseClicked(MouseEvent me) the co-ords of the click are obtained.

* if they are within the confines of the rectangle rect, console output System.out.println("inside box") is displayed
* in either case the click co-ords are displayed in the console

I'm getting the co-ords of the mouse clicks but no message when the click is inside the box

import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
/*
Experiment 04 was successful. So now (Experiment 05) I must try and see if I can identify mouse clicks that occur within the rectangle.
*/

public class AFrame extends Frame implements MouseListener {
ARectangle rect;
public AFrame(ARectangle rect) {

[Code] ....

View Replies View Related

Swing/AWT/SWT :: Method To Draw Triangle When Click On Specific Button

Mar 8, 2015

I'm trying to do a method which will draw a triangle and then the method will be called when we click on a specific button. How I must proceed.

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 :: JEditorPane Show Image When Event Click On Href

Mar 29, 2014

I want show one image when i click on one "href". I have write this code....

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Desktop;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;

[Code] ......

View Replies View Related

Swing/AWT/SWT :: How To Show And Hide Panel In One JButton Click Event

Nov 23, 2014

In JButton's click event, I wanto to show a JPanel to print the message "Processing" on the screen. Before JButton's click logic end, hide the JPanel.

Actually, JPanel is not displayed. I do not know why.When msgPanel .setVisible(false); is commented out, JPanel is normally displayed .But do not know how to hide it when JButton's click logic is finished.

Here is the code.

 loadBtn.addActionListener(new ActionListener() {
  @Override
  public void actionPerformed(ActionEvent arg0) {
   JPanel msgPanel = new JPanel(rootFrame);
   // Show the message JPanel

[Code] .....

View Replies View Related







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