jframe

NetBeans program linking

1 main program 2 JFrame programs. How do I use the main program to call the JFrames to run during the main programs execution chromatically? (One at a time, one pops up user interacts and hits ok, the next frame pops up) I've tried using this, but it executes both of the frames at the same time. EventQueue.invokeLater(new Runn...

How to add a WindowListener to an external event.

This is my code I have developed. This is the main program which holds and executes each external JFrame for my Game. chooseGender is an external program which is nothing but a JFrame and its components. My goal for this is when chooseGender executes, it has 2 buttons for options (male, female) when the user picks one, an actionListene...

calling variables from external JFrames

I have a Java game i'm creating and each window is a seperate JFrame with its own components. How would I get about calling variables from other .java programs? Not quite sure how to do that. ...

Java: Component.printAll() problem.

Hi. I'm trying to print a JFrame using the PrintUtilities Class: package util; import java.awt.*; import javax.swing.*; import java.awt.print.*; public class PrintUtilities implements Printable { private Component componentToBePrinted; public static void printComponent(Component c) { new PrintUtilities(c).print(); } publ...

Paint Swing Component to PDF using iText

I have a JFrame, which i wish to save as a PDF. How do i paint this JFrame using iText? public PrintFrameToPDF(JFrame bill) { try { Document d = new Document(); PdfWriter writer = PdfWriter.getInstance(d, new FileOutputStream ("sample.pdf")); d.open (); // HOW ? d.close (); } catch...

How to close a JFrame based window with a JButton click event

I am new to the whole Java Swing/AWT dialogs (which explains how amateurish this dialog below looks like, any help in arranging it better is welcome :) and I am struggling to close this popUp window when any of the two JButtons are clicked. I have already tried options like frame.dispose(), frame.setVisible(false) and even SwingUtilitie...

How would I code when a item has been selected in a JList?

I have a JList with 5 options in it and when one of the items becomes selected or clicked i want the text area next to it to show a paragraph of text relative to the item clicked. It should do this for each item in the list but I cant seem to find how to do it in the API How would my program know if an item in the JList was selected so ...

Simple JFrame dialog displaying JButton

First off, I am real new to Java Swing/AWT and not intricately familiar with the workings of JFrame, JPanel & JButton. I want to just display a simple PopUp dialog with a some text and a couple JButtons and it should exit when any of the two buttons are clicked. I have most of that logic in this class, however I'm still struggling to mak...

Why is my simple JFrame displaying weird?

I am a newbie at Java Swing/AWT and I have this code following working for a simple PopUp dialog which closes on any of the JButtons beind clicked, but displays real wonky. Does anybody have suggestions on what and how to fix? import java.awt.Color; import java.awt.Component; import java.awt.Dimension; import java.awt.Font; import java....

Question about Alignment in Java

Hi I create jFrame and put some components on it . I put Jpanel on it also in the left side of JFram when I change the size of the JFrame , the location of panel (Accourding Left Side of the JFram ) changed ... How can I keep the same space between the panel and the left edge of JFrame Is there Layout benefits me ?? mabey this ima...

JFrame not appearing on mouse click Location (SSCCE included)

Hello everyone, I am trying to make a JFrame appear on mousePressed Location but I keep failing and it get's annoying :( Any ideas what isn't working? import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.MouseAdapter; import java.awt.event...

Java JFrame keeping focus when visible

Hello everyone, I am not sure if I have set the right title for this post - so it is possible that there's already a post for what I am looking for, if that's the case feel free to close this and redirect me - what I am trying to do is this: When a JFrame is poped the user not to be able to click anywhere else in the gui unless that win...

Java tournament bracket

I'm working on a java application which requires the creation of a tournament bracket to take in event results, and I would like to display this tournament in a JFrame if possible, it needs to show 2,4,8,16, etc original players. I want to dynamically generate this using a jcombobox to ask the user how many players they want in the event...

e.getWindow().dispose() is not working?

Hi Guys, I have a main program which calls a JFrame to get User information, If a user press submit I am storing the information in POJO and getting it into Main program. If User clicks on Exit, I want to dispose the JFrame and want to exit the main program as well after executing one logging statement in main method. If I use - th...

How to place JButtons at a certain coordinate in a JFrame

Hi, I want to know how to place JButtons at a particular coordinate in the JFrame. All day I have seen layouts. This does not suit my purpose. I would prefer something like setBounds. Rumour has it that it does not work but setLocation does. I tried it but, the program disregards the setLocation line and sets it to a Layout. CODE i...

Java program exits when I click OK button in JOptionPane.showMessageDialog

Hi, when I click the OK button in second.java program, the program exit the program. I want it not to exit (since there is a thread running). I tried removing setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE). CODE import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swin...

Jframe does not remember it' s position after minimizing

Hi My problem is that , The Jframe window does not remember it's position after minimizing ....suppose I minimize at co'ordiates (45,89)..but after maximizing it again open at (37,28)..means at different co-ordinates ..i want that jframe should open at the same position...after maximizing..like remeber it's position.. please help ...

How to place a JButton at a desired location in a JFrame using java

Hey, I want to put a Jbutton on a particular coordinate in a JFrame. I put setBounds for the JPanel (which I placed on the JFrame) and also setBounds for the JButton. However, they dont seem to function as expected. My Output: My Code: import java.awt.Color; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing...

Java Swing: How to access variables in a 2nd frame from the first frame?

I'm programming a desktop application in JAVA usin NetBeans. My question is this: 1st: I have a Jframe that is the principal frame of the application. 2nd: In some moment I want to create a new object of some kind, so I press addButton y create a new JFrame (I create a new class window that extends Jframe) with some text fields in it...

JButtons fail to appear in the JFrame

Hi, I have code that displays a menu and 4 JButtons in a JFrame. I tested the code last night and everything was working fine. Now the JButtons do not appear in the JFrame today in the morning. I tried doing in Eclipse and still I got the same result. The output I am getting : My code: import java.awt.Color; import javax.swing.J...