jpanel

create an hotspot and set an image without background (like earth icon) to my panel

Hi I try to create a hotspot by Extends of canvas and I try to add it on a panel which is painted by images. So I must draw an icon (image) instead of clear rectangle of the screen. To do that I override the paint method to draw the icon I want to use. So far there is no problem; the hotspot works correctly and the icon is painted i...

KeyListener problem

In my apllication i am using a jpanel in which i want to add a key listener. I did it. But it doesnot work. Is it because i am using a swingworker to update the contents of the panel every second. Here is my code to update the panel RenderedImage image = ImageIO.read(new ByteArrayInputStream((byte[]) get())); Graphics graphics...

How can I change jtable height at runtime

I hava a JFrame with multiple JPanels of similar width aligned one below other. I use one of these JPanels to display a JTable which is the last JPanel of the lot. This JPanel has a JScrollpane as a child component. This is where I try to add my table dynamically. Initial height of this JScrollpane is set to 40. I designed above templat...

How to draw on JPanel on fixed position?

I have JPanel wrapped in JScrollPane and I want the rectangle to be drawn always on the same position = moving with scrollbars wont affect the visibility of the rectangle. I tried following code: public void paintComponent(Graphics g) { g.setColor(Color.red); g.drawRect(50, (int)getVisibleRect().getY(), 20 , 20); ...

java: how to make srollable panel with radio button and labels inside?

Hi, I got a JScrollPane in which I want to place a list of radio buttons and labels. My problem is the panel doesn't scroll, I suppose it's because i didn't set a viewport, but how can I set it when I have to many components? My code looks something like this: JScrollPane panel = new JScrollPane(); JRadioButton myRadio; JLabel myLabel;...

Bad event on java panel

Hi I have a java panel with 4 buttons. When I click on of these buttons, a new frame appears and the first is hidden with setVisibile(false). On that new window, I have another button, but when i click it, I got the event corresponding to the fourth button of the first window. Clicking the button again does the trick, but of course t...

How did I center a jpanel in a jpanel with netbeans?

With Netbeans I've succeded center a jpanel with fixed size, within an other jpanel. Now I can't repeat it - only copy it. How did I do? (or should I do to center x and y a jpanel with fixed size in another jpanel). The result differs in code: Working - search for .addContainerGap( and see next not working: javax.swing.GroupL...

Make JFrame / JPanel unclickable

I have a JFrame with an associated JPanel which fill the screen, both having setFocusable(false) and in Front another JFrame with a Jpanel with a fixed size and centered (both are unmoveable). In this 'front' Panel theres a game, but when i click on the background Frame the front Panel moves to the background i only see the (dark grey) b...

Removing JPanel from a JFrame in netbeans

So, I have several JPanels that contain buttons, labels, etc. that I want to switch between from a main JFrame. Currently I am trying to use the this.add(JPanelname); method and this.remove(JPanelname); with the validate(); and repaint(); methods The problem is it will add the panel to the JFrame but it will not remove it. I am not sur...

Applet panels, one fixed size, and dynamic JTextField

Hi, I need an applet which contains one panel. The panel needs to be 550x400 pixels, the JTextField needs to be under the panel dynamic size. I want it to be like this: [topPanel] [textPanel] However I am trying this, and it seems like the panel is filling all the space. The code: import java.awt.BorderLayout; import java.awt.Color; im...

JPanel background image

This is my code, it indeed finds the image so that is not my concern, my concern is how to make that image be the background of the panel. I'm trying to work with Graphics but i doesnt work, any ideas?? please?? try { java.net.URL imgURL = MAINWINDOW.class.getResource(imagen); Image imgFondo = javax.imageio.Imag...

Java:How to align JPanels

I have this code but it doesn't work: jPanel1.add(jLabel1); jPanel2.add(jButton1); jPanel2.add(jButton2); jPanel3.add(jPanel1,jPanel1.TOP_ALIGNMENT); jPanel3.add(jPanel2,jPanel2.BOTTOM_ALIGNMENT); setContentPane(jPanel3); pack(); Please tell me why! ...

Laying out JPanels to make a simple GUI

Hello, first of all, this is more or less my first GUI and ive learned Java for not more then a week, so it might contain some serious programming errors. What i have right now is: Buttons and labels are part of OptionPanel and are on the left, DrawingPanel is about 5x5 px in size and is on the right. What I am trying to do is a simpl...

Is there a Swing JPanel toolbar background that fits all OSs?

I'm using a JToolBar to have a toolbar on my application, but I don't like the look of it. Actually, there's basically no look, no background and the buttons are flat when the mouse is not over them. This is on Windows. How can I have a better look for this? Something that would fit better on Windows? Maybe something like the ToolStrip ...

Add method in JPanel created using GUI builder

I have GUI created using netbeans GUI builder. I want to add there an object (let's try with button) after pressing a JButton The very simple code which I wrote in ActionListener and works: button1.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { panel2.add(new JButton("X"));...

Problem painting JPanel gradient background with a JLabel on it

I have the following code to paint a JPanel's background: @Override public void paintComponent(Graphics g) { UIDefaults uid = UIManager.getDefaults(); Graphics2D g2d = (Graphics2D)g; Dimension d = this.getSize(); g2d.setPaint(new GradientPaint(0, 0, uid.getColor("ToolBar.light"), 0, d.height, uid.getColor("ToolBar.shad...

Problem painting JLabel class to another JPanel class

I have created a class that extends JLabel to use as my object moving around a JPanel for a game. import javax.swing.*; public class Head extends JLabel { int xpos; int ypos; int xvel; int yvel; ImageIcon chickie = new ImageIcon( "C:\\Users\\jjpotter.MSDOM1\\Pictures\\clavalle.jpg"); JLabel myLabel = new JLabel(chickie...

JFrame not working correctly

This is making me very angry, I have worked on this for 2 days, have 2 books open and have looked through them, and STILL can't get this program to run the way I want it run. I'm getting to the point where if this doesn't help, I quit. I want a SIMPLE Frame application. It has a JComboBox centered at the top. Next to it is a text field...

JPanel does not generate MouseEvents when cursor is on child components

It is a bit strange for me but JPanel does not generate MouseEvents when cursor is on child components: JTextField and JToolBar but it generates MouseEvents when cursor is on JLabel. Could someone explaind me why? Is there any way to force JPanel to generate events even if mouse is on child components? ...

How to set JPanel size?

I'm using Netbean's form creator and I'm trying out some things. I'm not sure if it's the layout manager, but when I create my own JPanel and add it to the main content pane of the my window, the size of the panel always maximizes inside the FrameView no matter what re-dimensioning methodology I use such as setSize or setPreferred size. ...