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

  • Home
  • SEARCH
  • 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 8907849
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:01:19+00:00 2026-06-15T03:01:19+00:00

I made a custom component so I could display images and the like, but

  • 0

I made a custom component so I could display images and the like, but it refuses to use anchor properly and centers at the top. Does anyone have a fix? Also, if anyone can point me to an easier layout I might switch, but I already use a lot of GridBag so it would be hard.

Test class for general testing:

package com.launcher.test;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;

import com.launcher.swing.ModViewer;

public class Test extends JFrame implements ActionListener {
private static final long serialVersionUID = 1L;

public GridBagConstraints gbc = new GridBagConstraints();

public static void main(String[] args) {
    new Test();
}

public Test() {
    super("Super Installer");
    JPanel j = new JPanel(new GridBagLayout());
    addObjs(j);
    this.add(j);
    this.setSize(500, 500);
    this.setVisible(true);
}

public void addObjs(JPanel j) {
    setGBC(0, 0);
    gbc.weighty = 1.0;
    gbc.anchor = GridBagConstraints.NORTHWEST;
    gbc.gridwidth = 2;
    gbc.gridheight = 2;
    gbc.ipadx = 50;
    j.add(new ModViewer(), gbc);
    setGBC(2, 0);
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.NORTHEAST;
    j.add(new JButton("Add Mod"));
}

private void setGBC(int i, int j) {
    gbc.gridx = i;
    gbc.gridy = j;
}

@Override
public void actionPerformed(ActionEvent e) {
}

}

ModViewer class, essentially a box:

package com.launcher.swing;

import java.awt.Color;
import java.awt.Dimension;

import javax.swing.BorderFactory;
import javax.swing.JPanel;

import com.launcher.Main;

@SuppressWarnings("serial")
public class ModViewer extends JPanel {

public ModViewer() {
    setBorder(BorderFactory.createCompoundBorder(
            BorderFactory.createLineBorder(Color.black),
            BorderFactory.createEmptyBorder(0, 0, 250, 250)));
    setPreferredSize(new Dimension(250, 250));
}
}
  • 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-15T03:01:20+00:00Added an answer on June 15, 2026 at 3:01 am

    To get positioning to work for the GridBagConstraints.NORTHWEST anchor position, you need to set the weight in the X axis:

    gbc.weightx = 1.0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I made custom component like this: my.Cmp = function(opt_domHelper) { goog.ui.Component.call(this, opt_domHelper); ... };
I made a composite component and declared a custom namespace in my taglib like
I've made custom adapter and call notifyDataSetChanged() then data updates. But after call notifyDataSetChanged()
I have made a Custom Component in XML, consisting of a button with an
Made a custom ListCellRenderer: import java.awt.Component; import javax.swing.JCheckBox; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel;
I made a custom DatePicker that extends the android DatePicker UI component. I needed
I'd like to customize the look of JPopupMenu so i made a custom class
I made a custom component in Joomla 2.5, and I need to reference custom
I created a custom component made up of UIView and it gets added as
I have this very simple custom component, made out of two Labels : _left

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.