jpanel

java drawing rect in panel

ı draw rect on to jpanel but it is only seeing when changing the active operation system window. ...

Java: pass an event to another component

Sorry I don't know if this is very clear, but I'm pretty new to Java. So I have a JFrame with a BorderLayout containing a JPanel and a JButton. What I want to do is when something happens in my JPanel, I want for example change the text of the JButton, or enable/disable it. How would I do that? How can I access the JButton from the JP...

How do I get hold of the margins of the Paper when using java printing?

I'm trying to print a JPanel with some painted graphics on it (overriding paintComponent). The graphics is so big that they wont fit on a single page and therefor I'm letting it span across multiple pages. My problem lies within the fact that if I let the user choose the pageFormat/Paper type by calling: PrintRequestAttributeSet aset =...

Getting the colour of where you have clicked on a JPanel?

I only want a method to activate if the pixel that is clicked is white. How would I implement this? Trying to look for a method that returns the colour at a coord, but I can't find one. ...

how to display a JTable in a JPanel with Java ?

hi, all in title thanks for your answers ...

adding jpanel into a jframe. netbeans

i am particularly using netbeans gui editor and i am new to gui i have a jframe created and I added jtabbedpanel. inside the jtabbedpanel i have 2 panels that i call standard and compact i have set standardPanel = new ImagePanel(); which ImagePanel.java is located on different java file how am I suppose to put a panel on different...

Losing Focus From A JTextField

After I use my textfield I can't get a jpanel that click on back into focus for my keylistener. It works for the mouselistener but all other keystrokes keep being detected by the textfield not the jpanel. The panel has been setFocusable(true) and works fine until i give the textfield the keyboard focus. It's like the textfield won't rel...

How to add an image dynamically at runtime in java

I've been trying to load up an image dynamically in runtime for the longest time and have taken a look at other posts on this site and have yet to find exactly the thing that will work. I am trying to load an image while my GUI is running (making it in runtime) and have tried various things. Right now, I have found the easiest way to c...

Java Swing transparent JPanels problem

I'm having A JLayeredPane where I add 3 JPanels. I make the JPanels transparent (no background is set and setOpaque(false)). I draw lines on the JPanels and only the line on the last JPanel which has been added is visible. The lines of the other JPanels are not visible through that top JPanel (even if I have added different zIndexes whe...

Reinstantiating a GUI (JFrame) object

Hi guys, basically I want my JFrame to become a completely new JFrame object when an event is triggered. I have some code that basically calls [CODE]GUI gui = new GUI(x, y)[/CODE] the only problem I'm having is that as well as creating the new GUI object, it is not deleting the old window. Can anyone tell me how to get rid of the old win...

Swapping out the center JPanel in a BorderLayout

I have a JPanel sitting inside the center position of a BorderLayout of a JFrame. How can I swap out the current JPanel for a new one? ...

Java Swing - How to disable a JPanel?

I have several JComponents on a JPanel and I want to disable all of those components when I press a Start button. At present, I am disabling all of the components explicitly by component1.setEnabled(false); : : But Is there anyway by which I can disable all of the components at once? I tried to disable the JPanel to which these compo...

How can I align all elements to the left in JPanel?

I would like to have all elements in my JPanel to be aligned to the left. I try to do it in the following way: JPanel panel = new JPanel(); panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); panel.setAlignmentX(Component.LEFT_ALIGNMENT); As a result Java use left side of all elements as a position of the element and then put all...

Incorrect sizing of a JPanel in a JScrollPane In Java 1.5

Hi, I am making an image loading component which consists of a JPanel containing a JScrollPane, which in turn contains another JPanel. What this component does is allows images to be dropped on top of it, after which point the image is loaded and the inner most JPanel is set to the size of the image dropped. This in turn causes the sc...

JPanel: both implementing my own paintComponent() and rendering children doesn't work

I'm extending a JPanel to display a game board, and adding a JEditorPane at the bottom to hold some status text. Unfortunately, the game board renders just fine, but the JEditorPane is just a blank gray area until I highlight the text in it, when it will render whatever text is highlighted (but not the rest). If I'm understanding Swing...

Netbeans JCalendar Panel

Hello all This code inside a JFrame form created in netbeans works fine as i'm trying to put a JCalendar in a panel that i create manually. JCalendar myCalendar =new JCalendar(); JPanel customPanel = new JPanel(); customPanel.setSize(400, 250); customPanel.setBorder(new LineBorder(Color.BLACK)); customPanel.add(myCalendar); this.add(cus...

JPanel not listening to key event when there is a child component with JButton on it

I'm working on a map editor for my college project. And I had a problem that the map panel is not listening key event while it should. This happens when I add a ToolBarPane (which extends JPanel) with JComponent such as JButton, JComboBox that implements ActionListener on it AND the map panel (which extends the JPanel) together on to the...

Java's Swing seems to be changing the layout from Card Layout

I am having some pretty strange symptoms with JPanels and CardLayout. Essentially, I have cards which act as "pages" since I can only hold 12 cells on the grid, and I display each page as a card, and clicking -> and <- buttons change pages accordingly (or that's the idea). Because this data is representing a changing model, every five se...

Revalidate JPanel's parent frame

I want my panel to fit the frame when I show/hide fields. How could I notify to the parent frame to revalidate? I thought about pass the frame to my panel's constructor, but I think may have a way this is already done. I remember that there was a protected attribute in JPanel, but there isn't.. maybe i remembering the wrong component. ...

java nested for() loop throws ArrayIndexOutOfBoundsException

I'm working through a JPanel exercise in a Java book. I'm tasked with creating a 5x4 grid using GridLayout. When I loop through the container to add panels and buttons, the first add() throws the OOB exception. What am I doing wrong? package mineField; import java.awt.*; import javax.swing.*; @SuppressWarnings("serial") public class...