jpanel

Listening for action on internal JPanel from a JFrame

Hi, I have a JFrame that has a BottomPanel (a class I made that extends JPanel) inside it. And inside that JPanel is another JPanel called DicePanel(that again extends JPanel). In DicePanel there is a button called 'End Turn' that when clicked should end the players current turn for the board game the program is based on. I want to some...

Java - set opacity in JPanel

Let's say I want to make the opacity of a JPanel %20 viewable? I don't mean setOpaque (draw or not draw) or setVisible (show or hide)... I mean make it see-through JPanel.. you know? Is this possible? ...

Displaying a JComponent inside a JPanel on a JFrame

I am failing to display a JComponent inside a JPanel on a JFrame. The following does not work. JComponent component = ... panel.add(component, BorderLayout.CENTER); frame.add(panel, BorderLayout.CENTER); But if I add the JComponent to the JFrame[like frame.add(component, BorderLayout.CENTER);], it displays the contents. Any ideas ...

JTable: Buttons in Custom Panel in Cell

Hello everyone, I want to be able to have a JPanel in a cell with a JButton that does some work when clicked. I looked for howtos about Cell Editors, but all examples talk about replacing the cell with another component (e.g. replace an int with a JTextField etc.) My situation is a little different: I have the following ADT class My...

How long does it take for a JPanel to update it's height?

import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.util.Random; public class dots extends JPanel implements KeyListener, ComponentListener{ //JPanel extended so that we can overwrite paintComponent and draw the dots, KeyListener so that we can capture keypresses Random rand = new Random(); JFrame frame; bo...

Where is the place to setSize of subcomponents

I have class extended from JPanel. This class contains several other JComponents and a lot of painting. What I did and I know it isn't correct is, I overrided the paintComponent for the paintings, so far so good. But I also set the location and the size for all subcomponents in this method, because they depend on the getWidth and getHe...

Java drawing on JPanel which on a JFrame

Hi I have a JFrame and there are two JPanels on top of it. My intention is to draw on the JPanels. Can anyone please share any Java code? ...

Why will BoxLayout not allow me to change the width of a JButton but let me change the height?

I'm trying to get the Layout of a JDialog of mine to fit a particular look that a program in which I'm porting to Java has, I've used several LayoutManagers before with great success yet for some reason I cannot seem to get this working at all. My goal is to have the Right (East) side of the JDialog contain a "Find Next" and "Cancel" but...

how to use a variable in various JPanel?

Hi, I’m new in Java. I use alternately various JPanel in a JFrame. And I would like to know how can I use a variable declared in a JPanel, in another JPanel? Thank you for your collaboration. Best regards. Daniel ...

Need Multiple JPanel's to respond its own mouse click events.

I have multiple JPanels on my application, however I cannot figure out how to detect which exactly which one was clicked. In my MouseListener, I have the argument e but my method isn't working Early in my code I declare multiple JPanels and a listener object. PuzzleListener plist = new PuzzleListener(); JPanel puzzle_board = ...

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...

jscrollpane in a jpanel

i want to have a scrollpane inside a panel which the scrollpane cover the whole panel. how can i do that? ...

Cannot add items to custom JPanel

My issues is that I have created a JPanel that draws a gradient as a background. But when I go to add components to it (like a JButton) it does nothing... Please help! import java.awt.Color; import java.awt.Dimension; import java.awt.Font; import java.awt.GradientPaint; import java.awt.Graphics; import java.awt.Graphics2D; import java....

Java JTextArea that auto-resizes and scrolls

I have a JTextArea in a JPanel. How can I have the JTextArea fill the whole JPanel and resize when the JPanel resizes and scroll when too much text is typed in? ...

Logic to move an item in the circular boundary only

I'm newbie to Game programming. I'm trying to develp a simple shooting game. The game ground which I'm trying is a circular one. The game has one shooter and 5 driods. The shooter and the driods have to move with-in the circular area only. Following is the code snippet i tried. I tried implementing the game using the State design patter...

Java - GUI's, Panels, and Subclassing.

I'm reading an introduction to Java book. I'm about three/fourths of the way through the GUI section, and learning about add different JComponents to a JFrame to create a UI. I'm confused about one thing, though. The book (in the examples) created a Frame, and then added 4 panels by subclassing one after the other. (In other words: It e...

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 - JPanel and KeyListener Problem.

I have a JFrame with 3 panels. I extend an App class, and then add three panels to it, like so: JPanel controlButtonsPanel = new GameControlButtons(); controlButtonsPanel.setPreferredSize(new Dimension(801,60)); controlButtonsPanel.setBorder(new LineBorder(Color.white, 1)); constraints.anchor = GridBagConstraints...

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...

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 ...