Swing/AWT/SWT :: Window To Submit Data Freezing When Created Inside Mouse Clicked Event
Feb 18, 2014
I'm trying to right a GUI in swing, and as part of my program, I want to open a secondary window out of the main window when a mouse clicks on the main window. Then, once I click a button on the secondary window, I want that window to close and submit data to the main window (like an info form). I have almost figured out how to do this, except for one problem. By putting a variable inside my form window called "ready," and then in my main window running a loop that constantly checks if ready is true and doesn't proceed until its true, I can create the form window, modify the values in it (currently just one value called "difficulty" that's modified by a jSlider), and then when i click the "begin" button, ready is changed to true, the form window closes, and the main window can proceed. However, when I try to put the while loop checking the ready variable inside a mouseClicked method in the main window, the form window freezes when it opens, and you can't see any of its content or modify it in any way (you can't even close it).
Here is my code:
//form window class
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
public class formWindow extends JFrame {
private JTextField instructions1;
I have created a gui which accepts username in the text field and once clicking on submit button it fetches user details and throws it on gui via JTable.
But when i click submit for the second time using different username the background process goes well and good the vector that i pass to jtable changes with new data but the values in gui still contain the old data.
I am using netbeans swing to do my little project . I have one table which is populated by data from a database. I also have another table which should be populated when a user selects a certain row in the first table.Both table have only one column. The logic is when a user selects on row 1,the data in that row should be obtained and should be used to search for certain entities in the database which are returned and used to populate table 2.So after a user selects row1 and decides to select row2 the second table should be updated accordingly. I have attached the java file
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package UI;
I am working on a simple app that should emulate a desktop with some icons that you can drag around. I was instructed to use the MouseListener and MouseMotionListener. The icons should drag starting at the point where the mouse originally clicked down on it (ie not dragging from the top right corner).
I am drawing my icons to a jpanel, and I seem to be having two problems:The hitboxes are offThe icon is being dragged from the top right corner, despite having setup up a mouse offset at the beginning of the drag..Here are the relevant classes, the Desktop.draw() method is being called from my DrawPanel
import java.awt.*; import javax.swing.*; import java.awt.event.*; public class Desktop implements MouseListener, MouseMotionListener{ static DesktopIcon[] icons;
So for a test i have a small array set as a jlist which is the contents of my jscrollpane, and it appears as if nothing is there until i adjust the window size by dragging it out or in... whats going on?
I have a JFrame where some elements (one, for now) have to be centered manually on the contentPane when resizing the window or changing the window state. Resizing event (componentResized) works fine but the windowStateChanged event is causing problems because it doesn't seem to "update" the contentPane's new size properly - it keeps the previous value although the window's size is obviously changed. This can be seen by simply printing the result of getSize called on contentPane.
Centering is done by programmatically changing the constraint of the component (using putConstraint, SpringLayout). The issue is that getWidth used in that method returns "wrong" values which results in an uncentered component. Maybe another listener is needed here?
Additional info: Eclipse with WindowBuilder, Linux Mint 15, Java 1.7
I know about SSCCE guidelines but I cannot make this particular example both ready to compile and short.For unknown reasons, I am unable to post the code example. I keep getting this - "Post denied. New posts are limited by number of URLs it may contain and checked if it doesn't contain forbidden words."
addWindowStateListener(new WindowStateListener() { // no "@Override" was generated but it is the same with it public void windowStateChanged(WindowEvent e) { System.out.println("EVENT: " + contentPane.getSize() + ", " + getExtendedState() + ", " + e.getOldState()); // amusingly, states are actually correct - interchanging between 0 (Frame.NORMAL) and 6 (Frame.MAXIMIZED_BOTH) when I maximize and "unmaximize" tfArrayPanelCenter();
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) {
What it's supposed to do: This code is supposed to see if the clicked card is selected. If it's not, select it and show the player where it can move / attack. If it is selected, then find out what card the player clicked on. If he clicked on the card that was already selected, deselect it. If he clicks on a friendly card (same playerID), then select that card. If he clicks on an enemy card (different playerID), attack that card. If he clicks on a tile, move it to that tile.
The problem: However, line 24-58 give me a bit of a problem. Right now, it works fine BECAUSE lines 46-58 are commented (which also means the unit can't move). If I uncomment those lines, the unit becomes able to move, however, lines 34-46 cease working...
Java Code:
@Override public void mouseClicked(MouseEvent e) { mainloop: for (int i = 0; i < Main.cards.size(); i++) { Card c = (Card) Main.cards.get(i); if (Card.cardSelected == null) {// Contains / Is not selected if (c.contains(e.getX(), e.getY())) { Tile.reset(); Card.reset(); Card.cardSelected = c;
I have created a DefaultTableModel tablel as a Global variable. The table is then created and attached to a Grid bag layout. Then I want to call the table again in another method to add rows of data into it. Hopefully that makes sense.
So the addrow for the table is located in the final method private class CalcButtonListener implements ActionListener
When I debug the code, deftablemodel variable is carrying NULL data.
Also to make things even more complicated, The actual headers for the table aren't showing up,... not entirely sure why though.
I am new to javafx I start using it instead of swing i used the scene builder for my forms the problem i faced i don't know how to have main screen with menu bar at top and depending the select from the menu it will open other windows and those window must be inside my window just like for example netbeans.
I don't need to open new window in separate i need all windows inside my main window and controlling over them minimize maximize perhaps.
treeView.setOnMouseClicked(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent mouseEvent) { if (mouseEvent.getClickCount() == 2 && mouseEvent.getButton() == MouseButton.PRIMARY) { // Some action } } });
For some reason when I click on a tab body I can also perform the listener action. How I can add additional statement to perform the action only if I select node?
I develop a desktop soft use javafx8, and remove default border (e.g. title and close/min/max button), now use mouse left key click the taskbar icon is nothing,i want click the taskbar icon,if stage it's show then hidden, if stage it's hidden then show it,the problem is I can't capture any mouse click event,so i can't show or hidden my stage.
So I am working on an ABV calculator for some practice, and one problem I am running into is that I am unable to set a JLabel properly on the top of the window that is created. It will display the text with no problem, but only on one column. Is there a way to center a JLabel across 2 columns? The label I am working with is titleL.
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.text.DecimalFormat; public class Beer_Calculator extends JFrame
I have create as short example which contains two classes Cat and Dog followed by a switch statement in the main method.
Class Cat
public class Cat { private String name; //Setter public void setName(String pName) {name = pName;} //Getter public String getName() {return name;} // Constructor public Cat(String catName) {name = catName;}
[code]....
My Issue is that after creating the objects within the switch statement, is there a way to return the objects back to the main method once created within the switch ?
I have a WindowClosing(WindowEvent e) method, but when I close my window it isn't doing anything inside the method. I am making a launcher and I want to make it so when the actual game window is closed it makes the launcher window visible again.
Java Code: public void windowClosing(WindowEvent e) { this.jf.setVisible(true); } mh_sh_highlight_all('java');
I'm writing a simple application, that provides a Swing GUI to a bounded-buffer problem. The application is composed by:
- Main.java: it creates a map of four threads (four instances of the class MyThread). Also it creates a shared database (an instance of the class Database) between the four threads.
- MyThread.java: it's an extension of Thread, and it shows a Swing GUI associated to this thread. Each thread is associated a GUI.
- GUI.java
- Database.java: it's an extension of ArrayList and and it can contain a maximum of five elements. An element is an instance of the class User. Also it implements put() and extract() method consistent with the algorithm of bounded-buffer problem.
- DatabaseException.java: it's a simple message.
- User.java
public class Main { public static void main(String[] args) { Database db = new Database(); Map<String, Thread> tdg_m = new HashMap(); for (int i = 1; i <= 4; i++) { tdg_m.put("T" + i, new MyThread(db));
[Code] .....
The issue is the following. When the database is full, and i try to put an element, the GUI freezes. The same problem occurs when I try to extract an element from the empty database.
My program has just "File" and "Help" in the menubar when "File" is clicked, there is an exit item that closes when clicked.i want the "About" item in "Help" to open a new window, what's wrong with my code?here is it:
i have a jsp page which contains two text areas inside two separate form tags. i want to submit unicode date in one textarea and display it in another. But nothing is working for me. i have to show basically all Indian Languages and english as well. here is the code of it
The class does get compiled but the submit button doesn't work?
/** * Orchestration class for Account */ import java.awt.*; //Importing the java.awt.* class import java.awt.event.*;//Importing the java.awt.event.* class import javax.swing.*;//Importing the javax.swing. class public class AccountDemo extends JFrame { /// initializes the variables in the container
My code below creates the 2 files successfully, but it is not able to write the sample data into the newly created file. I can't figure out the reason why.
Another strange thing is that when I tried inserting System.out.println calls for debugging, nothing prints out.