Questions tagged [jpanel]

JPanel is a container in the Java Swing Framework that allows custom rendering using layout managers. JPanels can be nested for flexibility. There is also a jQuery plugin with the same name that provides accordions, tabs, and fieldsets from simple container mark up.

JPanel is a container in the Java Swing Framework that allows custom rendering using layout managers. JPanels can be nested for flexibility. There is also a jQuery plugin with the same name that provides accordions, tabs, and fieldsets from simple container mark up.

Resources:

7557 questions
11
votes
3 answers

How to have Collapsable/Expandable JPanel in Java Swing

I want a JPanel that can be Collapsed or Expanded when user clicks on a text/icon on its border. I need this type of panel due to space crunch in my application. I read about CollapsiblePanel class but not sure how to use it.. I think SwingX is…
Nayan Soni
  • 1,001
  • 3
  • 12
  • 22
11
votes
5 answers

Automatically size JPanel inside JFrame

I have a JPanel subclass on which I add buttons, labels, tables, etc. To show on screen it I use JFrame: MainPanel mainPanel = new MainPanel(); //JPanel subclass JFrame mainFrame = new JFrame(); mainFrame.setTitle("main window…
Igor
  • 1,258
  • 2
  • 14
  • 20
11
votes
5 answers

MouseListener for JPanel missing mouseClicked events

I have a JPanel that I have created a MouseListener for and I am seeing some behavior that I can't explain. Usually when I click the mouse within the JPanel, I see the following events fire: mousePressed mouseReleased mouseClicked On some…
BillMan
  • 9,434
  • 9
  • 32
  • 52
11
votes
3 answers

How to right-justify icon in a JLabel?

For a JLabel with icon, if you setHorizontalTextPosition(SwingConstants.LEADING), the icon is painted right after text, no matter how wide the label is. This is particularly bad for a list, as the icons would be all over the place depending on how…
Geoffrey Zheng
  • 6,562
  • 2
  • 38
  • 47
11
votes
2 answers

adding JLayeredPane to JPanel

I am trying to add a JLayeredPane to a JPanel and then add an image (JLabel icon) and a button to the JLayeredPane, but neither show up. I've tested the image without the button and the layeredpane so I know that works. Here is some of the code I…
asawilliams
  • 2,908
  • 2
  • 30
  • 54
11
votes
4 answers

How to fit Image size to JFrame Size?

I have a JPanel into a JFrame. I loaded a picture on the JPanel but its shown just a part of the picture: This is the part of the code where i did it: JPanel panelImg = new JPanel() { public void paintComponent(Graphics g) { Image…
user1715408
11
votes
5 answers

Adding JPanel to JFrame

I have a program in which a JPanel is added to a JFrame: public class Test{ Test2 test = new Test2(); JFrame frame = new JFrame(); Test(){ ... frame.setLayout(new BorderLayout()); frame.add(test, BorderLayout.CENTER); …
Anonymous181
  • 1,863
  • 6
  • 24
  • 27
10
votes
3 answers

Drawing an Image to a JPanel within a JFrame

I am designing a program that contains two JPanels within a JFrame, one is for holding an image, the other for holding GUI components(Searchfields etc). I am wondering how do I draw the Image to the first JPanel within the JFrame? Here is a sample…
MattTheHack
  • 1,354
  • 7
  • 28
  • 48
10
votes
6 answers

Painting over the top of components in Swing?

I have a JPanel added to a JViewport, and the panel has several other panels added to it. I'm trying to implement a dragging selection, where you can select more than one component by dragging the mouse. The only problem I'm facing is that the…
rtheunissen
  • 7,347
  • 5
  • 34
  • 65
10
votes
1 answer

How to repaint a JPanel after have drawn on it?

I have a component that inherits from JPanel, I draw a grid on it. Now I have a JComboBox and I want the user to be able to choose the grid size here and then press a button to make the grid change (repaint the grid). The thing is that it paints the…
Aerozeek
  • 495
  • 1
  • 3
  • 11
10
votes
3 answers

Is there anyway to "pack" a JPanel?

Is there any thing I can do to make my JPanel pack like a JFrame, or do something like that. I want to do this instead of giving it dimensions. Please comment if any addition info is needed. Thanks.
MattS
  • 113
  • 2
  • 3
  • 11
10
votes
3 answers

Is there any way to force GridLayout to leave empty cells?

I have a JTabbedPane with 2 JPanels set to GridLayout(13, 11). The first JPanel has enough of the cells filled out that it leaves the empty cells. The second JPanel has significantly fewer cells filled and this results in each button getting…
Pentarctagon
  • 413
  • 2
  • 5
  • 12
10
votes
2 answers

What are the benefits to painting on a JPanel vs. JComponent?

So in a recent answer, someone commented this (in regards to painting): "This is probably some kind of illness of 90% of Swing Programmers: When they make their own component, they always extend JPanel instead of JComponent. Why?" I'm still fairly…
Paul Samsotha
  • 205,037
  • 37
  • 486
  • 720
10
votes
3 answers

JOptionPane with username and password input

I have my own Dialog pop up with two textfields, two JLabel and a "ok" JButton. The pop up is a login window. The window works perfect I just want to know how I am able to add a "cancel" JButton, so the user is able to cancel the login. Here is my…
Gerret
  • 2,948
  • 4
  • 18
  • 28
10
votes
1 answer

How To Add A MouseListener To A Frame

I want to add a mouselistener to mt JFrame frame but when i do frame.addMouseListener(this) i get an error that i cannot use this in a static method I am making an application that detects a click of the mouse then displays it in int…
ndfkj asdkfh
  • 316
  • 1
  • 5
  • 15