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
367
votes
14 answers

How to add an image to a JPanel?

I have a JPanel to which I'd like to add JPEG and PNG images that I generate on the fly. All the examples I've seen so far in the Swing Tutorials, specially in the Swing examples use ImageIcons. I'm generating these images as byte arrays, and are…
Leonel
  • 28,541
  • 26
  • 76
  • 103
123
votes
4 answers

JPanel Padding in Java

I have a formatting question for my Java swing application. It should be fairly straightforward, but I am having difficulty finding any aid (Every topic seems to be regarding removing any default padding in JPanel). The text in my various JPanels…
Connor
  • 1,943
  • 5
  • 16
  • 13
111
votes
5 answers

Java: Difference between the setPreferredSize() and setSize() methods in components

What is the main difference between setSize() and setPreferredSize(). Sometimes I used setSize(), sometimes setPreferredSize(), sometimes one does what I want, sometimes the other. What call should I use for JFrames and JPanels?
David Robles
  • 9,477
  • 8
  • 37
  • 47
62
votes
4 answers

add controls vertically instead of horizontally using flow layout

I am adding checkboxes on JPanel in FlowLayout the checkboxes are being added horizontally. I want to add checkboxes vertically on the Panel. What is the possible solution?
adesh
  • 1,157
  • 3
  • 18
  • 28
54
votes
3 answers

Align text in JLabel to the right

I have a JPanel with some JLabel added with the add() method of JPanel. I want to align the JLabel to the right like the image below but I don't know how to do that. Any Idea? Thanks!
Luca
  • 1,704
  • 3
  • 29
  • 42
50
votes
4 answers

How to draw in JPanel? (Swing/graphics Java)

I'm working on a project in which I am trying to make a paint program. So far I've used Netbeans to create a GUI and set up the program. As of right now I am able to call all the coordinated necessary to draw inside it but I am very confused with…
Nick R
  • 543
  • 2
  • 6
  • 13
49
votes
3 answers

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…
Roman
  • 124,451
  • 167
  • 349
  • 456
49
votes
2 answers

What does .pack() do?

I am learning about JPanel and GridLayout , this snippet of code will produce a simple JPanel with 6 buttons package testing; import java.io.*; import java.util.*; import java.security.*; import javax.xml.bind.DatatypeConverter; import…
Computernerd
  • 7,378
  • 18
  • 66
  • 95
47
votes
3 answers

Difference between JPanel, JFrame, JComponent, and JApplet

I'm making a physics simulator for fun and I was looking up graphics tutorials when I tried to figure out the difference between all these J's. Can somebody elaborate on them or perhaps provide a link to a helpful source?
Andyroo
  • 471
  • 1
  • 5
  • 3
47
votes
14 answers

How do I change JPanel inside a JFrame on the fly?

To put it simple, there's a simple java swing app that consists of JFrame with some components in it. One of the components is a JPanel that is meant to be replaced by another JPanel on user action. So, what's the correct way of doing such a thing?…
yanchenko
  • 56,576
  • 33
  • 147
  • 165
43
votes
2 answers

JPanel vs JFrame in Java

I am learning Java gui. The way I learnt to create a window is to inherit or Extend JFrame class and it is good to use it, as JFrame contains all the properties of a Window. Now If I want to add something to this window, I need to use add() method.…
Naruto
  • 1,710
  • 7
  • 28
  • 39
36
votes
6 answers

What is the relation between ContentPane and JPanel?

I found one example in which buttons are added to panels (instances of JPanel) then panels are added to the the containers (instances generated by getContentPane()) and then containers are, by the construction, included into the JFrame (the…
Roman
  • 124,451
  • 167
  • 349
  • 456
34
votes
6 answers

Java Swing - how to show a panel on top of another panel?

I wish to have an internal (non window) dialog to ask for member input. I would like the dialog to be placed centrally on an existing JPanel. I have looked at layeredpanes and these seem unusable due to only having a single layout manager (or no…
Pool
  • 11,999
  • 14
  • 68
  • 78
33
votes
4 answers

Add scroll into text area

How can I add the scroll bar to my text area. I have tried with this code but it's not working. middlePanel=new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), "Display Area")); // create the middle panel components display =…
Ravi
  • 401
  • 2
  • 8
  • 12
30
votes
7 answers

How to set a transparent background of JPanel?

Can JPanels background be set to transparent? My frame is has two JPanels: Image Panel and Feature Panel. Feature Panel is overlapping Image Panel. The Image Panel is working as a background and it loads image from a remote URL. On Feature…
Imran
  • 847
  • 2
  • 9
  • 9
1
2 3
99 100