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 9018493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:32:27+00:00 2026-06-16T04:32:27+00:00

I am adding a 2 jpanel (CENTER AND PAGE_END) to another Jpanel that goes

  • 0

I am adding a 2 jpanel (CENTER AND PAGE_END) to another Jpanel that goes in a JFrame. There is a HUGE gap between the 2 panels (panneauDateDebut and panneauDateFin) that I would like to eliminate. I have tried to set them in different configurations (start/center, start/end, center/end) but without luck. How can this be done ?

edit to have a working code

import java.awt.BorderLayout;
import java.awt.ComponentOrientation;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Frame;
import java.awt.GridLayout;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class CreerModificationAbsence extends JDialog {

    private JPanel modificationAbsence1, modificationAbsence2,
            modificationAbsence3, panneauDateDebut, panneauDateFin;
    private JButton modifier, annuler;
    private JLabel raison, prenomNomEmpl, prenomNomChef;
    private JComboBox<String> raisonC, heureDebutC, heureFinC, minuteDebutC,
            minuteFinC;
    private JTextField prenomNomEmplT, prenomnomChefT;
    private final String[] raisonAbsence = { "Malade" };

    private JLabel dateDebut, dateFin;
    private JTextField dateDebutT, dateFinT;

    private final String[] heures = { "00" };
    private final String[] minutes = { "00", "15", "30", "45" };

    private BorderLayout gestionnaireComposant;
    private GridLayout gridGestionnaireComposant;
    private FlowLayout panneauMilieuLayout;
    final FlowLayout gestionnaireComposantBas;

    public CreerModificationAbsence() {
        super((Frame) null, "Modification - Absence d'employé", true);

        setPreferredSize(new Dimension(600, 250));
        setAlwaysOnTop(true);
        setResizable(false);
        setLocation(400, 200);
        setAlwaysOnTop(true);
        gestionnaireComposant = new BorderLayout();
        this.getContentPane().setLayout(gestionnaireComposant);

        // Modification Panneau Haut

        modificationAbsence1 = new JPanel();

        gridGestionnaireComposant = new GridLayout(3, 2, 2, 2);
        modificationAbsence1.setLayout(gridGestionnaireComposant);

        raison = new JLabel("Raison : ");
        raisonC = new JComboBox<>(raisonAbsence);
        raisonC.setEditable(true);
        prenomNomEmpl = new JLabel("Prénom et Nom de l'employé : ");
        prenomNomEmplT = new JTextField();
        prenomNomChef = new JLabel("Prénom et Nom du chef d'équipe : ");
        prenomnomChefT = new JTextField();

        modificationAbsence1.add(raison);
        modificationAbsence1.add(raisonC);
        modificationAbsence1.add(prenomNomEmpl);
        modificationAbsence1.add(prenomNomEmplT);
        modificationAbsence1.add(prenomNomChef);
        modificationAbsence1.add(prenomnomChefT);

        // Modification Panneau Milieu

        modificationAbsence2 = new JPanel();
        panneauDateDebut = new JPanel();
        panneauDateFin = new JPanel();

        panneauMilieuLayout = new FlowLayout();

        panneauDateDebut.setLayout(panneauMilieuLayout);
        panneauDateDebut.setPreferredSize(new Dimension(600, 0));
                   panneauDateDebut.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);

        panneauDateFin.setLayout(panneauMilieuLayout);
        panneauDateFin.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
        panneauDateFin.setPreferredSize(new Dimension(600, 113));

        modificationAbsence2.setLayout(new BorderLayout(0,0));

        dateDebutT = new JTextField(12);
        heureDebutC = new JComboBox<>(heures);
        minuteDebutC = new JComboBox<>(minutes);
        dateFinT = new JTextField(12);
        heureFinC = new JComboBox<>(heures);
        minuteFinC = new JComboBox<>(minutes);

        dateDebut = new JLabel("Date de début :");
        dateFin = new JLabel("Date de fin :");

        dateDebutT.setPreferredSize(new Dimension(125, 20));
        dateFinT.setPreferredSize(new Dimension(125, 20));
        dateDebut.setPreferredSize(new Dimension(125, 20));
        dateFin.setPreferredSize(new Dimension(125, 20));
        heureDebutC.setPreferredSize(new Dimension(130, 20));
        minuteDebutC.setPreferredSize(new Dimension(130, 20));
        heureFinC.setPreferredSize(new Dimension(130, 20));
        minuteFinC.setPreferredSize(new Dimension(130, 20));

        panneauDateDebut.add(dateDebut);
        panneauDateDebut.add(dateDebutT);
        panneauDateDebut.add(heureDebutC);
        panneauDateDebut.add(minuteDebutC);
        panneauDateFin.add(dateFin);
        panneauDateFin.add(dateFinT);
        panneauDateFin.add(heureFinC);
        panneauDateFin.add(minuteFinC);
        modificationAbsence2.add(panneauDateDebut, BorderLayout.CENTER);
        modificationAbsence2.add(panneauDateFin, BorderLayout.PAGE_END);

        // Modification Panneau Bas

        modificationAbsence3 = new JPanel();
        gestionnaireComposantBas = new FlowLayout(FlowLayout.RIGHT);
        modificationAbsence3.setLayout(gestionnaireComposantBas);

        modifier = new JButton("Modifier");
        annuler = new JButton("Annuler");

        modificationAbsence3.add(modifier);
        modificationAbsence3.add(annuler);

        this.add(modificationAbsence1, BorderLayout.NORTH);
        this.add(modificationAbsence2, BorderLayout.CENTER);
        this.add(modificationAbsence3, BorderLayout.SOUTH);
        /*this.*/setDefaultCloseOperation(DISPOSE_ON_CLOSE);
        this.pack();
            /*this.*/setVisible(true);
    }

 public static void main(String s[]) {
    SwingUtilities.invokeLater(new Runnable() {

        @Override
        public void run() {
            CreerModificationAbsence textf = new CreerModificationAbsence();
        }
    });
}


}
  • 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-16T04:32:29+00:00Added an answer on June 16, 2026 at 4:32 am

    Well for starters (and for enders, don’t know if this is english or not): don’t call setPreferredSize()! This is what is causing all your problems. Stop using that (forever in your life ~ bad sense of humour, don’t take it harsh) and you will solve all your problems.

    Try this instead:

    import java.awt.BorderLayout;
    import java.awt.ComponentOrientation;
    import java.awt.FlowLayout;
    import java.awt.Frame;
    import java.awt.GridLayout;
    
    import javax.swing.JButton;
    import javax.swing.JComboBox;
    import javax.swing.JDialog;
    import javax.swing.JLabel;
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.SwingUtilities;
    
    public class CreerModificationAbsence extends JDialog {
    
        private JPanel modificationAbsence1, modificationAbsence2, modificationAbsence3, panneauDateDebut, panneauDateFin;
        private JButton modifier, annuler;
        private JLabel raison, prenomNomEmpl, prenomNomChef;
        private JComboBox<String> raisonC, heureDebutC, heureFinC, minuteDebutC, minuteFinC;
        private JTextField prenomNomEmplT, prenomnomChefT;
        private final String[] raisonAbsence = { "Malade" };
    
        private JLabel dateDebut, dateFin;
        private JTextField dateDebutT, dateFinT;
    
        private final String[] heures = { "00" };
        private final String[] minutes = { "00", "15", "30", "45" };
    
        private BorderLayout gestionnaireComposant;
        private GridLayout gridGestionnaireComposant;
        private FlowLayout panneauMilieuLayout;
        final FlowLayout gestionnaireComposantBas;
    
        public CreerModificationAbsence() {
            super((Frame) null, "Modification - Absence d'employé", true);
    
            // setPreferredSize(new Dimension(600, 250));
            setAlwaysOnTop(true);
            setResizable(false);
            setAlwaysOnTop(true);
            gestionnaireComposant = new BorderLayout();
            this.getContentPane().setLayout(gestionnaireComposant);
    
            // Modification Panneau Haut
    
            modificationAbsence1 = new JPanel();
    
            gridGestionnaireComposant = new GridLayout(3, 2, 2, 2);
            modificationAbsence1.setLayout(gridGestionnaireComposant);
    
            raison = new JLabel("Raison : ");
            raisonC = new JComboBox(raisonAbsence);
            raisonC.setEditable(true);
            prenomNomEmpl = new JLabel("Prénom et Nom de l'employé : ");
            prenomNomEmplT = new JTextField();
            prenomNomChef = new JLabel("Prénom et Nom du chef d'équipe : ");
            prenomnomChefT = new JTextField();
    
            modificationAbsence1.add(raison);
            modificationAbsence1.add(raisonC);
            modificationAbsence1.add(prenomNomEmpl);
            modificationAbsence1.add(prenomNomEmplT);
            modificationAbsence1.add(prenomNomChef);
            modificationAbsence1.add(prenomnomChefT);
    
            // Modification Panneau Milieu
    
            modificationAbsence2 = new JPanel();
            panneauDateDebut = new JPanel();
            panneauDateFin = new JPanel();
    
            panneauMilieuLayout = new FlowLayout();
    
            panneauDateDebut.setLayout(panneauMilieuLayout);
            panneauDateDebut.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    
            panneauDateFin.setLayout(panneauMilieuLayout);
            panneauDateFin.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    
            dateDebutT = new JTextField(12);
            heureDebutC = new JComboBox(heures);
            minuteDebutC = new JComboBox(minutes);
            dateFinT = new JTextField(12);
            heureFinC = new JComboBox(heures);
            minuteFinC = new JComboBox(minutes);
    
            dateDebut = new JLabel("Date de début :");
            dateFin = new JLabel("Date de fin :");
    
            panneauDateDebut.add(dateDebut);
            panneauDateDebut.add(dateDebutT);
            panneauDateDebut.add(heureDebutC);
            panneauDateDebut.add(minuteDebutC);
            panneauDateFin.add(dateFin);
            panneauDateFin.add(dateFinT);
            panneauDateFin.add(heureFinC);
            panneauDateFin.add(minuteFinC);
            modificationAbsence2.add(panneauDateDebut, BorderLayout.CENTER);
            modificationAbsence2.add(panneauDateFin, BorderLayout.PAGE_END);
    
            // Modification Panneau Bas
    
            modificationAbsence3 = new JPanel();
            gestionnaireComposantBas = new FlowLayout(FlowLayout.RIGHT);
            modificationAbsence3.setLayout(gestionnaireComposantBas);
    
            modifier = new JButton("Modifier");
            annuler = new JButton("Annuler");
    
            modificationAbsence3.add(modifier);
            modificationAbsence3.add(annuler);
    
            this.add(modificationAbsence1, BorderLayout.NORTH);
            this.add(modificationAbsence2, BorderLayout.CENTER);
            this.add(modificationAbsence3, BorderLayout.SOUTH);
            /*this.*/setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            this.pack();
            setLocationRelativeTo(null);
            /*this.*/setVisible(true);
        }
    
        public static void main(String s[]) {
            SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    CreerModificationAbsence textf = new CreerModificationAbsence();
                }
            });
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When adding a JPanel that has graphics to a JFrame , it's working fine.
I am adding JPanel to JFrame on a JButton click. It adds the JPanel
I'm adding some JCheckBox components to a JPanel at runtime. My problem is that
Is it possible to draw on a JFrame without adding a JPanel to it?
I'm working with a JFrame adding JPanel instances dynamically in the following way: private
There is a panel in a JFrame called a WatchPanel extends JPanel which uses
I am adding images to a JPanel but the images are getting cut off.
How to make a JPanel scrollable? I implemented the scrollable interface yet when adding
I'm having problems in adding a picture into JFrame, something is missing probebly or
I'm extending a JPanel to display a game board, and adding a JEditorPane at

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.