Skip to content

Tag: swing

Making a JFrame with a JMenuBar open in fullscreen

I have a JFrame that I want to add a menu bar to and then have that JFrame automatically open in fullscreen. If I just make a JFrame and set it to fullscreen with f.setExtendedState(f.getExtendedState()|JFrame.MAXIMIZED_BOTH ); that works fine: However, once I add a JMenuBar to that JFrame it will no longer o…

Why don’t size and preferredSize make this label bigger?

I’m building up a panel that will go in a larger program; the following program still illustrates my question, but it looks a bit more complicated than it absolutely has to because there are places I will add things later. I would like the currentImageLabel to be a standard size; I intend for it to get …

Java Swing JButton alignment – BoxLayout

Below is a small example where two radio buttons are offset too far to the left column. However, if I remove the “A” button above by commenting out this code: Then the 2 radio buttons are displayed as expected and not offset: How do I get the radio buttons aligned correctly like the second case, b…

Java paint line in existing JPanel with components

I’ve been searching for a few hours, including at other questions on stack such as. I need simplest way to draw a line in java in AWT panel but couldn’t find my answer. I have a panel gridbaglayout with multiple dynamically generated components. The class extends JFrame and thus can’t extend…

Java Swing unable to remove a component

I am trying to build a quiz game that rerender itself after user click on the button with answer. I have added an action listener to 4 buttons. When the button is clicked, it is suppose to reach the outer class which extend JFrame and remove the QuestionPanel that extends the JPanel. And then create a new Que…