How to set a transparent background of JPanel?

Calling setOpaque(false) on the upper JPanel should work. From your comment, it sounds like Swing painting may be broken somewhere – First – you probably wanted to override paintComponent() rather than paint() in whatever component you have paint() overridden in. Second – when you do override paintComponent(), you’ll first want to call super.paintComponent() first to … Read more

Can I add a component to a specific grid cell when a GridLayout is used?

No, you can’t add components at a specific cell. What you can do is add empty JPanel objects and hold on to references to them in an array, then add components to them in any order you want. Something like: int i = 3; int j = 4; JPanel[][] panelHolder = new JPanel[i][j]; setLayout(new GridLayout(i,j)); … Read more

Add scroll into text area

After adding JTextArea into JScrollPane here: scroll = new JScrollPane(display); You don’t need to add it again into other container like you do: middlePanel.add(display); Just remove that last line of code and it will work fine. Like this: middlePanel=new JPanel(); middlePanel.setBorder(new TitledBorder(new EtchedBorder(), “Display Area”)); // create the middle panel components display = new JTextArea(16, … Read more

What is the relation between ContentPane and JPanel?

It’s not two competing mechanisms – a JPanel is a Container (just look at the class hierarchy at the top of the JPanel javadocs). JFrame.getContentPane() just returns a Container to place the Components that you want to display in the JFrame. Internally, it’s using a JPanel (by default – you can change this by calling … Read more

JPanel vs JFrame in Java

You should not extend the JFrame class unnecessarily (only if you are adding extra functionality to the JFrame class) JFrame: JFrame extends Component and Container. It is a top level container used to represent the minimum requirements for a window. This includes Borders, resizability (is the JFrame resizeable?), title bar, controls (minimize/maximize allowed?), and event … Read more

Difference between JPanel, JFrame, JComponent, and JApplet

Those classes are common extension points for Java UI designs. First off, realize that they don’t necessarily have much to do with each other directly, so trying to find a relationship between them might be counterproductive. JApplet – A base class that let’s you write code that will run within the context of a browser, … Read more

What does .pack() do?

The pack method sizes the frame so that all its contents are at or above their preferred sizes. An alternative to pack is to establish a frame size explicitly by calling setSize or setBounds (which also sets the frame location). In general, using pack is preferable to calling setSize, since pack leaves the frame layout … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)