Horizontal scroll bar for JComboBox through multiple aspect

From [http://www.coderanch.com/t/432788/GUI/java/JComboBox-horizontall-scroll-bar] and [http://forums.sun.com/thread.jspa?threadID=5369365], I know that the technique to have a horizontal scroll bar for JComboBox.

However, their proposed solution are limited to the Look n Feel specific.

As you can see, the below excerpt key code is malfunctioning, if users are Linux machine with GTK + look n feel, or machine Windows with Nimbus look n feel.

How can I have a portable way to JComboBox able to have a horizontal scroll bar?

The complete source code is [http://jstock.cvs.sourceforge.net/viewvc/jstock/jstock/src/org/yccheok/jstock/gui/AutoCompleteJComboBox.java?revision=1.16 & view = markup]

The key code snippet are as follows:

package org.yccheok.jstock.gui;

public class AutoCompleteJComboBox extends JComboBox {

   @Override
    public void setUI(ComboBoxUI ui)
    {
        if (ui != null)
        {
            // Let's try our own customized UI.
            Class c = ui.getClass();
            final String myClass = "org.yccheok.jstock.gui.AutoCompleteJComboBox$My" + c.getSimpleName();

            try {
                ComboBoxUI myUI = (ComboBoxUI) Class.forName(myClass).newInstance();
                super.setUI(myUI);
                return;
            } catch (ClassNotFoundException ex) {
                log.error(null, ex);
            } catch (InstantiationException ex) {
                log.error(null, ex);
            } catch (IllegalAccessException ex) {
                log.error(null, ex);
            }
        }

        // Either null, or we fail to use our own customized UI.
        // Fall back to default.
        super.setUI(ui);
    }

    // This is a non-portable method to make combo box horizontal scroll bar.
    // Whenever there is a new look-n-feel, we need to manually provide the ComboBoxUI.
    // Any idea on how to make this portable?
    //
    protected static class MyWindowsComboBoxUI extends com.sun.java.swing.plaf.windows.WindowsComboBoxUI
    {
        @Override
        protected ComboPopup createPopup()
        {
            return new MyComboPopup(comboBox);
        }
    }

    protected static class MyMotifComboBoxUI extends com.sun.java.swing.plaf.motif.MotifComboBoxUI
    {
        @Override
        protected ComboPopup createPopup()
        {
            return new MyComboPopup(comboBox);
        }
    }

    protected static class MyMetalComboBoxUI extends javax.swing.plaf.metal.MetalComboBoxUI
    {
        @Override
        protected ComboPopup createPopup()
        {
            return new MyComboPopup(comboBox);
        }
    }

    private static class MyComboPopup extends BasicComboPopup
    {
        public MyComboPopup(JComboBox combo)
        {
            super(combo);
        }

        @Override
        public JScrollPane createScroller()
        {
            return new JScrollPane(list,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
                    JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        }
    }
}
Published by: 803903 on October 20, 2010 18:03

Darryl Burke wrote:
Purists will tell you that such things should not be done in a renderer

not too purist - but there are thingies you MUST NOT spread like that pollutes community knowledge ;-)

There is an official way (read: code of the heart itself does swing combo) to access the pop-up window and then do what you must

    private void adjustScrollBar(JComboBox box) {
        if (box.getItemCount() == 0) return;
        Object comp = box.getUI().getAccessibleChild(box, 0);
        if (!(comp instanceof JPopupMenu)) {
            return;
        }
        JPopupMenu popup = (JPopupMenu) comp;
        JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
        scrollPane.setHorizontalScrollBar(new JScrollBar(JScrollBar.HORIZONTAL));
        scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    }
    

Simply assign the scroll bar will work at any time after the creation of the drop-down list (BTW: assigning the horizontalScrollBar null got really... didn't even know it is valid). If you want to resize the drop-down list, you will need to do it in a popupMenuListener willBecomeVisible: at this time, all internal components are ready for touch-ups. Just for fun, set up the drop-down list to adapt to the requirements of the size of a JXTable used as a rendering component:

    private void adjustPopupWidth(JComboBox box) {
        if (box.getItemCount() == 0) return;
        Object comp = box.getUI().getAccessibleChild(box, 0);
        if (!(comp instanceof JPopupMenu)) {
            return;
        }
        JPopupMenu popup = (JPopupMenu) comp;
        JScrollPane scrollPane = (JScrollPane) popup.getComponent(0);
        Object value = box.getItemAt(0);
        Component rendererComp = box.getRenderer().getListCellRendererComponent(null, value, 0, false, false);
        if (rendererComp instanceof JXTable) {
            scrollPane.setColumnHeaderView(((JTable) rendererComp).getTableHeader());
        }
        Dimension prefSize = rendererComp.getPreferredSize();
        Dimension size = scrollPane.getPreferredSize();
        size.width = Math.max(size.width, prefSize.width);
        scrollPane.setPreferredSize(size);
        scrollPane.setMaximumSize(size);
        scrollPane.revalidate();
    }
    

and Yes, this is the example for setXXSize. But then, it isn't but application code a code 'in-house framework.

See you soon... and the real work
Jeanette

Tags: Java

Similar Questions

  • How to create a horizontal scroll bar for interactive report region?

    Hello

    I use APEX 4.2.5.00.08 and created interactive reports that contain many columns. However when viewing the results of the report, due to the large number of columns report/table data is outside of the region and a horizontal scroll bar appears in the window of my main browser. This seems not very good from the point of view of the customer/end user and I was wondering if it is possible the size of declare the region according to a specific size and have a scroll bar horizontal that it contains, so that users can view the rest of the report columns using the scroll instead bar rather than do what he done right now and go to the screen and having to use the main browsers horizontal scroll bar at the bottom.

    I tried on IE8, Chrome and Firefox 27.0.1 and get the same result. I tried to follow the ideas in this thread, in interactive report horizontal scroll bar, but nothing is.

    You have ideas on how I can get around this please?

    Concerning

    Hi user10248308


    Try this


    Step 1:-modify the interactive report

    Step 2:-under defination region-> header area

    put

    Step 3:-under area Defination-> foot of the region

    put


    Please come back if this is not yet resolved.

  • Horizontal scroll bar is missing in the region without borders

    Hello

    I use v4.2.1.00.08 APEX and used 24 theme.

    I'm not able to see the horizontal in the region without borders scroll bar when necessary. I just used the code inside the < style > tag to display the scroll bar, below

    #RPT .uRegionContent
    {
    overflow:auto;
    }
    
    

    It works, but now I can see the only horizontal scroll bar for this region not in the browser. Can someone help me get the horizontal scroll bar in the browser.

    horizontal.JPG

    I created a test case for this species,

    https://Apex.Oracle.com/pls/Apex/f?p=32974:3:8262817666057:no

    WS/Nations United/PWD: adhimaha/adhimaha/adhimaha

    Can someone help me on this...

    Thanks in advance,

    Adhi

    Lakshmi,

    Check in your page 9 of the application or the tab Test Pars control.

    hope this has solved your problem.

    changes made

    1. create the new model of the region as a region without borders copy model

    2. change the region class 'uIRRegion' instead of 'uRegion '.

    3. apply this classic report template.

    Leave.

  • Horizontal scroll bar in the model of interactive report region 5 Apex (universal theme)

    Hello

    We have migrated our application from 4.2 (theme: 21 scarlet) to 5.0 (changed to universal theme). Most of our reports are interactive reports and have more than 20 columns to display in the reports. 4.2 in the 'Region of report"model horizontal scroll bar came from bottom of page like below and has been easy for the user to scroll through the options to the right and see all the columns.

    Apex4.2.PNG

    In the universal theme apex 5 with 'interactive report' model in order to see the columns on the far right in the first lines user must scroll the vertical bar first, then scroll horizontal straight bar and vertical bar to go to the top


    Apex5.PNG


    How can you have the scroll as in 4.2 bar region of report model. I think that we need to make some changes in CSS and also need to copy the existing model and make changes and use this model in all reports.


    Thank you.

    RAM


    Hi Tim,.

    Thanks for the reply. I tried this option before posting forum. It did not work. Now, after changing position attribute fixed to the ' Page "(or region) in the report attributes section it works." " When we migrated the app at UT, he has been on 'None '. Problem solved now. Thank you.

  • A very large page, continues that will feature a horizontal scroll bar

    Hello, I am trying to create a simple portfolio site that simply has a long, horizontal page which will be wider than the browser window and therefore produce a horizontal scroll bar that can scroll through manually. It's probably something very simple to achieve, but I don't know how! Can I change the width of the page somehow?

    Any help would be appreciated! Thank you.

    Yes, you certainly want to learn some HTML & CSS. Ask yourself everything is really simple, however. As he has

    already been said, you only need to change the width of your wrapper div (or any div that you use as a container for your site).

    So assuming that you are using a div wrapper for your content, the HTML would look like this:

    all content and other divs would be placed here, within the envelope

    The CSS for this wrapper div would look like this:

    {#wrapper}

    Width: 3000px;<-------this sets="" the="" width="" of="" that="" div.="" 3000px="" really="" wide,="" so="" a="" scrollbar="" is="" created="" to="" view="" the="" rest="" of="" the="">

    }

  • How to get the horizontal scroll bar of a Table?

    Hi all

    According to my requirement, I display multiple records in a form in a tabular Format. But here I must show 21 columns in this table that is too high. I am able to view it, but because it I get a scroll bar horizontal to the screen as all columns not in the normal window screen space. But its weird since the research once I am to right scrolling columns, but bar header and Global buttons above are not displayed, they are related to the normal screen space.

    Is it possible to have a horizontal scroll bar only for this table instead of the whole screen so that on the slider, only the rows in the table will be beshifted ant had displayed?

    With our thanks
    Gerber

    try this approach.
    include an element of plain text before and an array element.
    include HTML tags in the raw text element to allow horizontal scrolling

    Prasanna-

  • Why the horizontal scroll bar does not disappear when windows are maximized, but reappears when minimize?

    I'm a fool to the computer. I fix my car and I don't fix my computer. If there is no easy solution, I'll pay someone to do it for me. So, is there an easy way to retrieve my horizontal scroll bar? I've updated to the latest Firefox (35). I restored my computer to an earlier date when everything was ok. I downloaded another browser (Chrome) to see if that would fix it. Nothing has worked. The system I use is Windows 7 64 bit. I tried not to do anything, because this has led to big problems in the past. Suggestions, or I need to take the machine to my fix - it person?

    Thanks for any assistance yu might be able to provide.

    Bingo! You have reason, cor - el. Thank you.

    I never noticed this before. Sometimes (when I'm too lazy to get up and do my glasses or cannot find them) I just increase the size of the window.

    To me it seemed that the scroll bar was still there, and then it wasn't. Hours lost, but a lesson learned. I did not mention that I am a fool to the computer, I don't?

    Thank you!!!

  • X 1163 projector shows smaller than the computer screen image and creates the horizontal scroll bar

    I just bought an Acer X 1163 projector for use in presentations. I like the brightness, size and features. I am disappointed to make a PowerPoint slideshow, you need to buy another remote, but it is an easy fix.

    Here's what's really about me!

    When I pull a Web site or other things on my laptop for the presentation, it has a horizontal scroll bar and does not fit it on the screen. I tried different settings and who are seeking an answer online, but can't find what I can do to get the image to display without a horizontal scroll bar.

    I'm almost beginning to panic that I bought this for a large presentation I have to give next week. I hope it's one of those stupid questions with an easy answer.

    Thanks in advance for your help.

    My techy boyfriend just called. Here is the solution. (It kills me when someone has a question asked and more later said: "never mind, I figured it" and never says how do to the next person to come.)

    The question seems to be in the computer resolution setting and how it automatically resets when plugging n the projector. To resolve this problem (at least in windows 7) follow these steps:

    Right click on the desktop

    Click on display

    Click on change display settings

    Select the 1366 x 768 resolution

    It shows exactly what I'm looking for now on my computer.

    Thank you for having a forum to ask in all cases

  • Horizontal scroll bar went

    Horizontal scroll bar on web pages has disappeared.  How can I get that back?

    Hello

    Check the right lower setting on IE - + 100% (can be defined below) - set if necessary.

    Also check the VIEW - ZOOM and VIEW - text size (the average is the default)

    ================================

    What antivirus/antispyware/security products do you have on the machine? Be one you have NEVER
    on this machine, including those you have uninstalled (they leave leftovers behind which can cause
    strange problems).

    If no joy there's something blocking perhaps.

    Start - All Programs - Accessories - System Tools - IE with no Addons - what works best?

    IE - Tools - Internet Options - Advanced - tab click on restore, and then click Reset - apply / OK

    IE - Tools - Internet Options - Security tab - click on reset all default areas - apply / OK

    Close and restart IE or IE with no addons

    not better?

    IE - tools - manage Addons (for sure disable SSV2 if she's here, it is no longer necessary but Java
    installs and it causes more questions - have you never update Java to go back in and turn it off again.) Search
    other possible problems.

    Windows Defender - tools - software explore - look for problems with programs that do not look right.
    Allowed are usually OK and "unauthorized" are not always bad. If in doubt about a program, ask
    topic here.

    Could be a free - BHOremover - BHO - standalone program, needs no installation, download and run.
    not all are bad, but some can cause your question (toolbars are BHO).
    http://securityxploded.com/bhoremover.php

    How to change, add or remove startup programs in Windows 7
    http://www.SevenForums.com/tutorials/1401-startup-programs-change.html

    Also get Malwarebytes - free - use as scanner only.

    http://www.Malwarebytes.org/

    --------------------------------

    Try these to erase corruption and missing/damaged file system repair or replacement.

    Run DiskCleanup - start - all programs - Accessories - System Tools - Disk Cleanup

    Start - type in the search box - find command top - RIGHT CLICK – RUN AS ADMIN

    sfc/scannow

    How to fix the system files of Windows 7 with the System File Checker
    http://www.SevenForums.com/tutorials/1538-SFC-SCANNOW-Command-System-File-Checker.html

    Then run checkdisk (chkdsk).

    How to run check disk in Windows 7
    http://www.SevenForums.com/tutorials/433-disk-check.html

    I hope this helps.

    Rob Brown - MS MVP - Windows Desktop Experience: Bike - Mark Twain said it right.

  • horizontal scroll bar to the APEX 5

    Off I want to say that I know that this question is almost identical to this position of ScrollBar is horizontal in the area of interactive report 5 (universal theme) Apex model or

    Problem is that their solution doesn't seem to work on our application for.

    Problem:

    After our 4.2 application migration, using a theme customized, universal theme 5.0.  We have a lot of interactive reports with a lot of columns.  When you use 4.2 the horizontal scroll bar is part of the 'window' and the user can scroll to view all additional columns at any time.

    Since we migrated to the universal theme the horizontal scroll bar appears in the report rather than the 'window' forcing users to scroll down the lines displayed to view additional columns.

    I tried as shown in the previous post to be sure in the attributes of the region, we set the Cap "fixed to" = page.

    and the Show maximize has been checked in the Options of the model.  Have tried the model "Interactive" both the model 'Standard '.

    We have always failed to get the horizontal scroll bar to move the window rather than in the report.

    According to me, I have to miss a step.  Any help would be appreciated.

    OK, alright its really bad, but I just noticed the report maximize button in the window

    When I press on the scroll bar jumps out of the window, as we wish.  We'll just have to educate people to use this button.  Amazing to see that a few days away from a question means for your home.

  • Horizontal scroll bar on table

    JDeveloper 12.1.3 using:

    I have af:table inside the af: panelCollection inside an af:gridCell.  Cell's width 100%, panelCollection AFStretchWidth style.

    The table is too wide to fit the width of the page.  So he has a horizontal scroll bar.  This is only if there are enough rows in the game currently questioned that he needs a vertical scroll bar.  But if there is no necessary vertical scroll bar, horizontal scroll bar is also absent.  You don't see the columns that are to the right of the frame.  Oddly enough - there is an exportCollection listener and if you export to Excel, you can see all the columns.  In addition, if you use the detachment of the panelCollection function and display the table in a pop-up, the horizontal scroll bar is present in the single table, and you can scroll through the columns to the right.

    I have a test application based on the HR diagram, and I can't do a malfunction in the way in which the actual application.  Scroll bars appear when they should.

    So I have to do something wrong in the real application.  Any thoughts?

    OK - it's not pretty, but it works:

    I set the width property of the table '97% '.  98%, it works on Chrome and Firefox, but not IE.  99% (or 98% on IE) displays a horizontal scroll bar, but it only scrolls across a few columns, the width of the table.  Same thing if I set the width to the sum of the widths of the columns.  With the help of AFStretchWidth on the table is not working at all - does not hurt, but the problem is still there.

    Not as pretty that I would because there is a small empty space to the right of the table (other 3%, I guess), but it is better that it works not.

  • Disappeared from my horizontal scroll bar.

    Disappeared from my horizontal scroll bar.  I opened Premiere Pro with ALT + SHIFT pressed down.  I installed CCleaner and it ran.  Subsequently uninstalled and reinstalled and the bar is not yet there.  I make videos for Christmas gifts and really need your help.  Thank you.

    Press the left button on the upper right part of X.

  • Horizontal scroll bar (Possible Bug)

    Hello

    I'm working on a site and I encountered a strange bug that adds a horizontal scroll bar on my page, and I have no idea why. Although there are elements that are outside the page, the scroll bar appears way before they near the edge of the browser window. This happens in Chrome, Safari, and Firefox.

    What is very strange, it is trying to solve the problem, I deleted several items in my file of available to muse, and I found what was causing the problem. I have blue bars which act as headings for each section, and they are not 100% width (and I don't want them to be), and they were not off the page. However, once that I removed those, stopped scrolling bar so soon indicating when to reduce the window of the browser. I added bars, one by one and found that depending on where to place the vertical bar will have an impact on the horizontal scroll bar. This seems to happen whenever my bar is played below y: 1030. I've added screenshots to show this, and I can email my Muse of Adobe support file.

    Some of you will notice that I don't have an item that hangs off the page, and it's true, I do not think it affects the issue I'm having. When I remove the rectangles blue as described in the previous paragraph, the site is behaving as expected, even with my ribbon attached to the page. The blue rectangles, the scroll bar appears before the browser window meets the Blue Ribbon.

    I spent a lot of time looking for a solution and playing with the elements on my site and page properties, and I can not solve the problem. Just that there is no scroll bar until the window is actually lower on the page.

    Screenshots:

    Thank you for the great repro case. It has been exceptionally helpful.

    You have exposed a bug that has probably been there forever which requires only the right combination of objects on the page and off the left of the page in order to be triggered. Let's write a bug to study for a future version. Unfortunately, the next major release is due soon, so this bug will not be fixed in time for this release.  https://creativecloud.adobeevents.com/ccnext

    A solution (that probably seems arbitrary, but should work in all cases) is to group the blue box with any other object. Sorry for the confusion and inconvenience.

  • Why do I get the horizontal scroll bar?

    Work on my first RWD - here, it's on a test server (index only page) http://www.sandiegohomegrown.com/testSDTG/index.html

    When I resize the browser and get to 1276 pixel anywhere I get a horizontal scroll bar.  Impossible for the life of understand me why!  If someone could take a look and give me some tips, some tips on how to solve the problems, I would be grateful.

    Thanks - Gary

    Get rid of the announcement of Google and it should work as expected.  As far as I know, Google ads are not because they have explicit height and width attributes that you cannot remove.

    Nancy O.

  • How can I remove the horizontal scroll bar

    Hello!  I am a new user of muse.  My website is almost finished, except for the nagging horizontal scroll bar at the bottom of the page.  I can't understand why it is there for the life of me.  My page is http://testwake1.businesscatalyst.com/index.html#home

    The black background, I have to adjust the length of the browser and which seems to be the question because if I delete it the horizontal scroll disappears.  What can I do to remove the bar or change the page correctly?  Thank you very much for your help!

    Eric

    On the PC, it seems to only do in Chrome... Exploerer and Firefox does not display a horizontal bar.

    You can also check the properties of the Site, under the menu file/Site Properties window and see if the browser scroll bars have the value Always or automatic.

Maybe you are looking for

  • Unable to connect a video call &amp; not ringing... Help, please!

    I use Skype for a few years now and have agreedthat Skype has its good days and bad. for the last two days, I've beentry to call my in-laws so they can chat with their grandchildren. We are bothonline in Skype, when I click to make the video call, it

  • need to fix the size of the text

    Text size problem.  My cat ran across the keyboard and press a button that caused the text to shrink size.  I tried to fix it through the display settings, but it does not work.  Is there a key that I can hit to the size big enough to read?

  • As a Christmas lights display

    When I start windows xp, that everything seems to go fine until my screen saying no signal and I beep cpu will beep a nd after that my sreen starts lighting up as if it was Christmas with all red green and so on and so forth with different colors hel

  • No. 64-bit to 32-bit series

    I have a question. I downloaded a copy of 32-bit Windows 7 Home premium and I want to use it in my notebook which is installed windows 7 Home premium 64-bit. can I activate my windows 7 Home premium 64-bit serial number in my laptop if I installed wi

  • Update of LR 5.7 perpetual student license

    I allowed perpetual student of 5.7 Lr, I want to update to permit perpetual student of Lr 6.5.x.How to do this?