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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:52:02+00:00 2026-06-04T19:52:02+00:00

I would like to create a textwidget/component wich looks like the firefox address bar.

  • 0

I would like to create a textwidget/component wich looks like the firefox address bar. I mean a Textfield wich allows me to place little Buttons inside the field (e.g. cancel/reload/…)

I tried customizing a JLayeredPane, by creating a custom layout manager which maximizes the Textfield, and places the remainder from right to left. My problem is that this gave painting issues, I would not always see the items I added over the textfield. This might be Jython related, I try suppling java.lang.Integer(1) to the JLayeredPane.add. However the Layers are ordered exactly reverse to what the documentation says.

TO cricumvent this I derived my own JLayeredPane class and redefined paint to call paintComponents which in turn iterates over all components and calls their paint method, starting with the textbox, the rest thereafter.

However I don’t always get the updates right away, meaning the buttons are hidden/only partly displayed and I can’t Interact with the button.

  1. What do I have to acutally see the update on screen (is it hidden in a buffer?))
  2. How can I make it so that I can interact with the buttons?
  3. How can I shorten the Texxtfield, so that the text starts scrolling to the front before I reach the end of the Textfield so that the text does not get hidden by the buttons? I still want the Textfields area to extend under the buttons

edit: the button is only displayed in the right place after i make the window smaller, after that it is also clickable

edit2:
I took the freedom to boil the answer down to this, which hides away a lot of that button code/unneccessary stuff

import java.awt.*;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import javax.swing.*;

public class playground {

    private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
    private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon");
    private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon");

    public playground() {
        JPanel panel = new JPanel();
        panel.setLayout(new BorderLayout());

        panel.add(makeButton(), BorderLayout.WEST);

        JTextField text = new JTextField(20);
        text.setBorder(null);
        panel.add(text, BorderLayout.CENTER);
        JPanel buttonsPanel = new JPanel();
        buttonsPanel.setOpaque(false);
        buttonsPanel.setLayout(new GridLayout(1, 2, 2, 2));

        buttonsPanel.add(makeButton());
        buttonsPanel.add(makeButton());

        panel.add(buttonsPanel, BorderLayout.EAST);
        panel.setBackground(text.getBackground());

        JMenuBar menuBar = new JMenuBar();
        menuBar.add(panel);
        menuBar.add(Box.createHorizontalGlue());
        JFrame frame = new JFrame("MenuGlueDemo");
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.add(menuBar);
        frame.pack();
        frame.setVisible(true);
    }

    public JToggleButton makeButton() {
        final JToggleButton button = new JToggleButton();
        button.setFocusable(false);
        button.setMargin(new Insets(0, 0, 0, 0));
        button.setContentAreaFilled(false);
        button.setBorder(null);

        button.setIcon((errorIcon));
        button.setRolloverIcon((infoIcon));
        button.setSelectedIcon(warnIcon);
        button.setPressedIcon(warnIcon);

        button.addItemListener(new ItemListener() {

            @Override
            public void itemStateChanged(ItemEvent e) {
                if (button.isSelected()) {
                } else {
                }
            }
        });

        return button;
    }

    public static void main(String[] args) {
        javax.swing.SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                playground menuGlueDemo = new playground();
            }
        });
    }
}
  • 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-04T19:52:03+00:00Added an answer on June 4, 2026 at 7:52 pm

    may be could it be simple by using JMenuBar, with Auto complete ComboBox / JFextField for example

    enter image description here

    import java.awt.ComponentOrientation;
    import javax.swing.*;
    
    public class MenuGlueDemo {
    
        public MenuGlueDemo() {
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(createMenu("Menu 1"));
            menuBar.add(createMenu("Menu 2"));
            menuBar.add(createMenu("Menu 3"));
            menuBar.add(new JSeparator());
            menuBar.add(new JButton("   Seach ....  "));
            menuBar.add(new JTextField("   Seach ....  "));
            menuBar.add(new JComboBox(new Object[]{"height", "length", "volume"}));
            menuBar.add(Box.createHorizontalGlue());
            menuBar.add(createMenu("About"));
            JFrame frame = new JFrame("MenuGlueDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(menuBar);
            frame.pack();
            frame.setVisible(true);
        }
    
        public JMenu createMenu(String title) {
            JMenu m = new JMenu(title);
            m.add("Menu item #1 in " + title);
            m.add("Menu item #2 in " + title);
            m.add("Menu item #3 in " + title);
            if (title.equals("About")) {
                m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }
            return m;
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    MenuGlueDemo menuGlueDemo = new MenuGlueDemo();
                }
            });
        }
    }
    

    EDIT

    I can simply but a text input and some buttons in a container with a proper layout and achieve [Textfield…] [B1] [B2] but I want [Textfield [B1] [B2]]

    enter image description here

    with proper LayoutManager

    import java.awt.*;
    import java.awt.event.ItemEvent;
    import java.awt.event.ItemListener;
    import javax.swing.*;
    
    public class MenuGlueDemo {
    
        private Icon errorIcon = UIManager.getIcon("OptionPane.errorIcon");
        private Icon infoIcon = UIManager.getIcon("OptionPane.informationIcon");
        private Icon warnIcon = UIManager.getIcon("OptionPane.warningIcon");
    
        public MenuGlueDemo() {
            JPanel panel = new JPanel();
            panel.setLayout(new BorderLayout());
            JButton button = new JButton();
            button.setFocusable(false);
            //button.setMargin(new Insets(0, 0, 0, 0));
            button.setContentAreaFilled(false);
            button.setIcon((errorIcon));
            button.setPressedIcon(warnIcon);
            panel.add(button, BorderLayout.WEST);
            JTextField text = new JTextField(20);
            text.setBorder(null);
            panel.add(text, BorderLayout.CENTER);
            JPanel buttonsPanel = new JPanel();
            buttonsPanel.setOpaque(false);
            buttonsPanel.setLayout(new GridLayout(1, 2, 2, 2));
            final JToggleButton toggleButton = new JToggleButton();
            toggleButton.setFocusable(false);
            toggleButton.setMargin(new Insets(0, 0, 0, 0));
            toggleButton.setContentAreaFilled(false);
            toggleButton.setIcon((errorIcon));
            toggleButton.setRolloverIcon((infoIcon));
            toggleButton.setSelectedIcon(warnIcon);
            toggleButton.setPressedIcon(warnIcon);
            toggleButton.addItemListener(new ItemListener() {
    
                @Override
                public void itemStateChanged(ItemEvent e) {
                    if (toggleButton.isSelected()) {
                    } else {
                    }
                }
            });
            buttonsPanel.add(toggleButton);
            final JToggleButton toggleButton1 = new JToggleButton();
            toggleButton1.setFocusable(false);
            toggleButton1.setMargin(new Insets(0, 0, 0, 0));
            toggleButton1.setContentAreaFilled(false);
            toggleButton1.setIcon((errorIcon));
            toggleButton1.setRolloverIcon((infoIcon));
            toggleButton1.setSelectedIcon(warnIcon);
            toggleButton1.setPressedIcon(warnIcon);
            toggleButton1.addItemListener(new ItemListener() {
    
                @Override
                public void itemStateChanged(ItemEvent e) {
                    if (toggleButton1.isSelected()) {
                    } else {
                    }
                }
            });
            buttonsPanel.add(toggleButton1);
            panel.add(buttonsPanel, BorderLayout.EAST);
            panel.setBackground(text.getBackground());
            JMenuBar menuBar = new JMenuBar();
            menuBar.add(createMenu("Menu 1"));
            menuBar.add(createMenu("Menu 2"));
            menuBar.add(createMenu("Menu 3"));
            menuBar.add(new JSeparator());
            menuBar.add(new JButton("   Seach ....  "));
            menuBar.add(panel);
            menuBar.add(new JComboBox(new Object[]{"height", "length", "volume"}));
            menuBar.add(Box.createHorizontalGlue());
            menuBar.add(createMenu("About"));
            JFrame frame = new JFrame("MenuGlueDemo");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            frame.add(menuBar);
            frame.pack();
            frame.setVisible(true);
        }
    
        private JMenu createMenu(String title) {
            JMenu m = new JMenu(title);
            m.add("Menu item #1 in " + title);
            m.add("Menu item #2 in " + title);
            m.add("Menu item #3 in " + title);
            if (title.equals("About")) {
                m.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
            }
            return m;
        }
    
        public static void main(String[] args) {
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
    
                @Override
                public void run() {
                    MenuGlueDemo menuGlueDemo = new MenuGlueDemo();
                }
            });
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i would like create a array of structure which have a dynamic array :
I would like to create a flash presentation for a web page. It would
I would like to create a COM object that runs in an out of
I would like to create a 'New Document' dialog similar to the Office 2007
I would like to create a UIBarButtonItem on my iPhone application which has two
I would like to create a class whose methods can be called from multiple
I would like to create a stored procedure with parameters that indicate which fields
I would like to create a custom document library where I use the standard
I would like to create a table to store device settings. The table has
I would like to create a template for new stored procedures for our development

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.