Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8593821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:04:41+00:00 2026-06-12T00:04:41+00:00

I have a class extending JPanel that I want to embed into a JFrame

  • 0

I have a class extending JPanel that I want to embed into a JFrame. The L&F is set to Nimbus, and the layout I’m using for the panel is a GridBagLayout.


When I gave the JAR to a friend, a JTextArea I intend to use as a log console started acting up and wouldn’t stay the size I set it to.

textAreaLog.setMinimumSize(new Dimension(295, 48));

I’m using WinXP SP2, and my friend’s using Win7 64-bit. Here’s a picture of how it looks on my PC (left) and his PC (right):

Image

Obviously I intended it to be the way I have it on my machine.


Here’s the relevant code (almost the whole class used for the panel):

package com.sassilization.mapfix.gui;

// Imports the package with the inner-workings of the application
import com.sassilization.mapfix.MapFixGenerator;

import java.awt.*;
import java.awt.event.*;

import javax.swing.*;

public class LogPanel extends JPanel {
    private static final long serialVersionUID = 8324191587703173738L;

    /*
    * Constructor
    */
    public LogPanel() {
        setPreferredSize(new Dimension(350, 70));
        // Creates a default Nimbus border
        setBorder(BorderFactory.createTitledBorder((String) null));
        setOpaque(false);

        setLayout(new GridBagLayout());
        // Calls the method which initializes all the components
        initComponents();
    }

    /*
    * Component declarations
    */
    private JButton buttonFgd;
    private JButton buttonHelp;
    private JButton buttonLogCopy;
    private JButton buttonLogDown;
    private JButton buttonLogUp;
    private JTextArea textAreaLog;
    private JToggleButton toggleButtonAppend;

    /*
    * Initializes and adds all the components to the panel
    */
    private void initComponents() {
        // The constraints used to lay out the components in a GBL
        GridBagConstraints gbc = new GridBagConstraints();

        // The brick button
        toggleButtonAppend = new JToggleButton(appendIcons[0]);
        toggleButtonAppend.setBorder(BorderFactory.createEmptyBorder());
        toggleButtonAppend.setToolTipText("Turn append mode on");
        toggleButtonAppend.addItemListener(new ItemListener() {
            public void itemStateChanged(ItemEvent event) {
                buttonAppendItemStateChanged(event);
            }
        });
        add(toggleButtonAppend, gbc);

        // The question mark button
        buttonHelp = new JButton(new ImageIcon(getClass().getResource("resources/help.png")));
        buttonHelp.setBorder(BorderFactory.createEmptyBorder());
        buttonHelp.setToolTipText("Open help");
        buttonHelp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // buttonHelpActionPerformed(event);
            }
        });
        gbc.gridy = 1;
        add(buttonHelp, gbc);

        // The white page button
        buttonFgd = new JButton(new ImageIcon(getClass().getResource("resources/page_white_put.png")));
        buttonFgd.setBorder(BorderFactory.createEmptyBorder());
        buttonFgd.setToolTipText("Extract FGD file");
        buttonFgd.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // buttonFgdActionPerformed(event);
            }
        });
        gbc.gridy = 2;
        add(buttonFgd, gbc);

        // The problematic JTextArea
        textAreaLog = new JTextArea();
        textAreaLog.setMinimumSize(new Dimension(295, 48));
        textAreaLog.setBorder(BorderFactory.createMatteBorder(0, 12, 0, 0,
                new ImageIcon(getClass().getResource("resources/border.png"))));
        textAreaLog.setBackground(new Color(0, 0, 0, 0));
        textAreaLog.setForeground(new Color(171, 193, 207));
        textAreaLog.setFont(new Font(null, Font.PLAIN, 9));
        textAreaLog.setLineWrap(true);
        textAreaLog.setWrapStyleWord(true);
        textAreaLog.setEditable(false);
        gbc.gridx = 1;
        gbc.gridy = 0;
        gbc.gridheight = 3;
        add(textAreaLog, gbc);

        // The up arrow button
        buttonLogUp = new JButton(new ImageIcon(getClass().getResource("resources/bullet_arrow_up.png")));
        buttonLogUp.setBorder(BorderFactory.createEmptyBorder());
        buttonLogUp.setContentAreaFilled(false);
        buttonLogUp.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // buttonLogUpActionPerformed(event);
            }
        });
        gbc.gridx = 2;
        gbc.gridheight = 1;
        add(buttonLogUp, gbc);

        // The floppy disk button
        buttonLogCopy = new JButton(new ImageIcon(getClass().getResource("resources/bullet_disk.png")));
        buttonLogCopy.setBorder(BorderFactory.createEmptyBorder());
        buttonLogCopy.setContentAreaFilled(false);
        buttonLogCopy.setToolTipText("Copy log to clipboard");
        buttonLogCopy.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // buttonLogCopyActionPerformed(event);
            }
        });
        gbc.gridy = 1;
        add(buttonLogCopy, gbc);

        // The down arrow button
        buttonLogDown = new JButton(new ImageIcon(getClass().getResource("resources/bullet_arrow_down.png")));
        buttonLogDown.setBorder(BorderFactory.createEmptyBorder());
        buttonLogDown.setContentAreaFilled(false);
        buttonLogDown.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent event) {
                // buttonLogDownActionPerformed(event);
            }
        });
        gbc.gridy = 2;
        add(buttonLogDown, gbc);
    }

    private ImageIcon appendIcons[] = { new ImageIcon(getClass().getResource("resources/brick.png")),
            new ImageIcon(getClass().getResource("resources/brick_add.png")) };

    /*
    * Event listener methods for the components go here.
    */
}

Furthermore, here’s the main JFrame class which instantiates the LogPanel, albeit uncommented. Included is also a download link for the JAR.

Link


I’m using JPanel.setMinimumSize() so I can tame the JTextArea without using a JScrollPane. I’m thinking the display inconsistency has to do with this. If I do use a JScrollPane, it messes up the panel layout completely, so I’d rather stay away.

Thanks in advance.


EDIT 1:

If I change the L&F to the default or the system L&F, I get the same issue my friend did; therefore, it’s most likely something to do with Nimbus itself.


EDIT 2:

It turns out there are differences in the Nimbus code between JDK6,
which I was using, and JDK7. I have since updated and replaced the
faulty code with setPreferredSize()—it works great now.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T00:04:42+00:00Added an answer on June 12, 2026 at 12:04 am

    I’ve found a solution:

    It turns out there are differences in the Nimbus code between JDK6,
    which I was using, and JDK7. I have since updated and replaced the
    faulty code with setPreferredSize()—it works great now.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a java class that extends from JPanel. The basic purpose of extending
I have a Class extending JFrame that is watching for a mouse click anywhere:
I have an intermediary class extending System.Web.UI.Page for all of my pages that require
Currently I have a class that is extending the ListActivity class. I need to
I have class that extend FragmentActivity in it I add fragment to layout as
Suppose I have class animal and classes cat and dog extending it. I want
I have a class extending JFrame which contains group of radioButtons and a submit
I have made a custom class extending Preferences. I have used that custom class
Say, I have a class Foo, extending class Bar. And I want to slightly
I have an abstract class AbstractEvent and some real classes extending it. I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.