jframe

Java JFrame Question

import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.*; public class tictac2 implements ActionListener{ static boolean blue = true; //used to keep track of turns. if true, blue's turn, else, red's turn. Blue is x, red is o static int bWins = 0, rWins = 0; JFrame mainW...

adding behavior when closing a JFrame

I have created a JFrame and I would like to associate a specific behaviour when this JFrame is closed. Is it possible? ...

Substance UI & undecorated JDialog/JFrame

I have noticed that while using the Substance UI for Java that when I set a new JFrame or JDialog to undecorated it is not honored. e.g. frame.setUndecorated(true); frame.setVisible(true); When run under Substance shows a decorated frame. When run under system default L&F shows an undecorated frame. Anyone have ideas for working ar...

JFrame resizable height ONLY

Hello, JFrame.setResizable(true) lets the user resize both the width and height of a window. Does a method exist which allows the user to ONLY resize the height? Thanks. Edit: The solutions below do NOT seem to work. On a 360x600 JFrame, setResizable(true); pack(); setMaximizedBounds(new java.awt.Rectangle(0, 0, 360, 1200)); setMaxi...

Java Swing main JFrame: why does SwingUtilities.getAncestorOfClass return null?

Hi folks, I intend to implement a Swing application which keeps all its JComponents within the main application window JFrame. It seems like clunky procedural code to give all my JPanel constructors a parameter referring to the JFrame. So some research uncovered SwingUtilities.getAncestorOfClass, which looked like the solution. But I c...

Java JFrame popup ordering (should be always on top but behind old JFrames)

Is it possible to maintain individual JFrame ordering? My java application populates individual JFrames always on top, My question is what could be the approach to populate another JFrames behind "already populated" JFrames but Always on top from other applications? Any suggestions, ideas appreciated. Thanks. ...

refresh JFrame after adding new Components

I want to add some new Components to my JFrame while runtime when pressing a button. This works so far, but i have to resize the window by hand to see the new components! is there any Action i can fire or a method to call to refresh the window? ...

Java; Getting insets before frame is visible

Assuming a normal JFrame, I'm trying to get the inset values before the frame is made visible. I can get these values fine once the frame is made visible (and i suppose I could create the jframe offscreen), but was wondering if there is some way to tickle Java into setting the insets before visibility. Prior to this call, all inset val...

java swing thread problem

In my java swing application am having a Jframe and Jlabel for displaying current time. here am using a thread for displaying time in jlablel which is added to the frame.my doubt is that when i dispose the jframe what will happen to the thread whether its running or stopped. ...

Java - JPanel won't show up on JFrame when overriding JFrame's paint

I have a JFrame on which I am using overriding the paint method to display some graphics. I also want to add a JPanel to it that will show up on top of the graphics. Right now, all I see is the graphics created from JFrame paint method. Here's my JPanel: public class NoteDraw extends JPanel { public NoteDraw() { setSize(20...

resize child panel when resizing parent JFrame

I have a JFrame which contains a JPanel. The frame can be resized by the user using the mouse. When the width of the frame is > 400, the jpanel inside's width is set to 10; otherwise 1080. In between the frame and the panel, there is also a JScrollBar. Here is my code: import java.awt.BorderLayout; import java.awt.Color; import java.a...

Java - Paint, JFrame, and Backgrounds

I'm trying to paint a Welcome Screen for my game, but only when the game loads. I don't want it to repaint everytime during the game. So I did this (where isStart is instantiated as true): public myClass(String name){ setSize(800, 800); setVisible(true); setResizable(false); runGame() } public void paint(Graphics g) { ...

Trying to figure out a formula for morphing a window

My goal is to use one method that moves two windows on the screen from the original location and size of the first window to the original location and size of the second. At first, I tried this: public void morphInto(final Window fromWindow, final Window toWindow) { stop(); final Rectangle FROM = fromWindow.getBounds(), DEST...

Java - JFrame, JPanel, Layout, and Clipping

I have three questions/problems. (NOTE - I don't have enough reputation to post pics, so I linked them. And I needed to obfuscate them...) 1) I created a panel that holds my game graphics (the player area). The panel is supposed to be 800x800 and clip everything that lies below and to the right. But when I add the graphics panel to a JF...

Java - GUI, Panel, and Data Accessing.

I'm making a game with three main panels and a few subpanels, and I'm confused about how you "connect" the panels and their data. I have my main class, which extends JFrame and adds three JPanels. Each of those panels is a subclass of JPanel. (Ex: JPanel gameControlPanel = new GameControlPanel(), where GameControlPanel is a class I crea...

How can I make my GUI Frame larger?

The problem is, I am unable to make it a dimension with 800x600. In other words, when I run the program, the frame is so small that I can not do anything with it. How can I make the frame larger? I have set the preferred size already ans set the canvas bounds. Then what is the problem? public class GameCanvas extends Canvas { pri...

Java - How to access/share data in game with JPanels.

I made a simple java game last week. At that time, one class extended Jframe and held the data (which comprised three other class, through composition) Now, I'm trying to make the same game, but with several JPanels. One panel will be the game graphics (basically the old JFrame shrunk into one panel). And there will be buttons and text ...

Why is this JPanel not sticking to the specified size?

So, I'm trying to learn Java Swing and custom components. I've created a JFrame, given it a background color, and added a JPanel: JFrame frame = new JFrame("Testing"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setSize(1000, 2000); frame.setBackground(Color.WHITE); JPanel jp = new JPanel(); jp.s...

swing: programmatic close of JFrame

What's the programmatic equivalent of clicking the close (x) button in the upper right corner of a JFrame? There's the dispose() method but that's not the same thing, since a JFrame can be set to do several different things upon closing (not to mention if there's a WindowListener involved) ...

Why isn't JMenu always on top?

The JMenu behaves normally until a JButton is used to update a JTable on the JFrame. Then the JMenu is mostly hidden by a JPanel (see images below). Shouldn't the JMenu always be on top when it is selected? Why has it been pushed to the back? The code that updates the table on jButtonAddActionPerformed is. public class MyClass extends j...