JScrollPane with Components?

hey guys, im writing a program and I have a JScrollPane and i want to have multiple JTextFields and radio buttons in it that work with the scroll pane so you can type something in on lets say field 1 and then scroll down to field 15 and type something into that one. is this possible? so far ive gotten them to show up in the scroll pane but the scroll bar doesnt even appear. ive tried setting the policy to ALWAYS but that little scroll block doesnt appear, only the bar itself thus making any fields below the windows bounds unaccessable. Any idea how to get this working?
Message was edited by:
HDL_CinC_Dragon

run this the 3 times to see the differences
import javax.swing.*;
import java.awt.*;
class Testing extends JFrame
  JPanel p = new JPanel(new GridLayout(0,1));
  JScrollPane sp = new JScrollPane(p);
  public Testing()
    setSize(600,400);
    setLocation(200,100);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    for(int x = 0; x < 50; x++)
       p.add(new JLabel("Hello World"));
    //sp.setPreferredSize(new Dimension(500,300));//test without this line, then with the line
    JPanel p1 = new JPanel();
    p1.add(sp);
    getContentPane().add(p1);
    getContentPane().add(sp);//comment out this line, uncomment above block
  public static void main(String[] args){new Testing().setVisible(true);}
}

Similar Messages

  • JScrollPane with scrollbar as needed packs to the wrong size.

    Hi!
    I just noticed a strange problem when packing a JScrollPane with scrollbar policy "as needed" and wondered if it's me or if it is a real bug in Swing.
    I create a JFrame with a JScrollPane in it and a JPanel as viewportview. The JPanel (called "stuffPanel") contains a few components which give it a preferred size, and the JScrollPane is set to grow as needed if the window grows. A button in the center of the stuffPanel will invoke pack() on the window when clicked.
    Now, if I resize the window such that the JScrollPane can't display the entire stuffPanel, I get scrollbars as expected. If I click the pack button the window correctly resizes to the preferred size (without scrollbars).
    On the other hand, if I resize the window to become larger than the preferred size and then click the pack button, the window (and the stuffPanel) is resized to include 17 pixels of extra size around the edges.
    Put simply, pack() will resize the JPanel to different sizes depending on whether the scrollbars of the JScrollPane were visible at the time. Note that this only occurs when you're using the "scrollbars as needed" scrollbar policy.
    An even more interesting situation occurs if you resize the window to include (for example) only horizontal scrollbars and then packs the window repeatedly...
    Code for a Java app which displays the strange behaviour is included below:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class TestJScrollPane {
      static {
        try {
          UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
        catch (Exception e) { }
      private JFrame mainWindow;
      public TestJScrollPane() {
        mainWindow = createMainWindow();
        mainWindow.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        mainWindow.pack();
        mainWindow.show();
      public JFrame createMainWindow() {
        JFrame window = new JFrame("Test of scrollpane");
        window.getContentPane().setLayout(new GridBagLayout());
        final JPanel stuffPanel = new JPanel();
        stuffPanel.setBorder(BorderFactory.createTitledBorder("Collection of stuff"));
        stuffPanel.setLayout(new GridBagLayout());
        JLabel stuffLabel = new JLabel("A label");
        JTextField stuffField = new JTextField(10);
        JButton stuffButton = new JButton("Pack the window");
        JList listOfStuff = new JList();
        listOfStuff.setListData(new String[] {"Fish", "Bird", "Mammal", "Insect", "Spider"});
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.gridx = 0;
        gbc.gridy = 0;
        stuffPanel.add(stuffLabel, gbc);
        gbc.gridx = 1;
        stuffPanel.add(stuffField, gbc);
        gbc.gridy = 1;
        gbc.gridx = 0;
        gbc.gridwidth = 2;
        stuffPanel.add(stuffButton, gbc);
        gbc.gridy = 2;
        gbc.fill = GridBagConstraints.BOTH;
        stuffPanel.add(listOfStuff, gbc);
        final JScrollPane scroller = new JScrollPane(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
        scroller.setViewportView(stuffPanel);
        gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weightx = 1;
        gbc.weighty = 1;
        window.getContentPane().add(scroller, gbc);
        stuffButton.addActionListener(new ActionListener() {
          public void actionPerformed(ActionEvent e) {
            mainWindow.pack();
            System.out.println("Stuff panel size: " + stuffPanel.getSize());
            System.out.println("Stuff panel preferred size:" + stuffPanel.getPreferredSize());
            System.out.println("Scroller size: " + scroller.getSize());
            System.out.println("Scroller preferred size: " + scroller.getPreferredSize());
        return window;
      public static void main(String[] args) {
        new TestJScrollPane();
    }

    Why would the JScrollPane be as big as the entire
    frame when you added 800x600 panels on all sides of
    it? It's going to be in the center surrounded by
    huge panels. Thanks, kablair. However, if you look at the code, these panels are not 800x600 on all sides. The north and south panels only add a combined height of 100, and the east and west panels only add a combined width of 100. so the whole window, minus insets, should be 900x700.
    Anyway, i took the advice of the guy above, and that has gotten me much closer. In the bigger app that I'm trying to calculate the size, now I'm only 2 pixels away from the true size, although I can't figure out what I'm forgetting.

  • Production order with components consumed from vendor consignment stock

    Hi expert,
    I have a production order with components and some of the components should be consumed from vendor consignment stock.
    When the order is created/released : is there  a possibility to have those components created with "special stock indicator" = 3 (consignement stock) by default?
    Thanks,
    P.

    Dear Pete,
    In my understanding it's not possible to populate this value as 3 - consignment stock in the component overview.This has to be
    done manually.
    Check in this way,by indicating a value in any of the material master field(for eg ABC indicator in MRP1 view) and if there's some
    value,then while saving the system populates for all those materials with this value as 3 by using some user exit or BADI.
    I'm not sure,it's only an idea,check and revert
    Regards
    Mangalraj.S

  • Problems with components in frames

    I have my applet (applet-application hybrid, actually) make a Frame and then add a few Components to it, like a Textfield and a Checkbox and a few buttons. On my Macintosh, everything renders fine, but in Windows, it will never draw the textfield or checkbox, only the buttons. Any idea why this is happenning? I'm sure the components are created and added and drawn in the Paint method of the frame, but they never show up and if they do they flicker on and off.
    This brings up another point that has been frustrating me ever since I started working with Components. Why can I only call setSize() or setLocation() within certain methods? To clarify, if I implement Runnable, and I try to setLocation in init(), it will fail, but in run() it works fine.
    I'm sure these are dumb questions, but from my perspective Java is doing a lot of stupid things that are merely confusing and frustrating me. It seems like once you set some attribute of an object it should remain like that. Why would the location of a checkbox or a button or a list change from init to run? It makes no sense to me and it forces me to make silly workarounds. This crap with frames and paint are so ridiculous that I can't even figure out a work around.
    Please help. I'm on the brink of scrapping this entire GUI that I've been slaving over. I'll post some cleaned up code if anyone wants to see what I'm talking about.

    Some layout managers doesn't care about setSize and setLocation is only needed when you build a GUI without a layout manager (setLayout(null)).
    And if your gui flickers, then it sounds like you are calling repaint in your paint method (that could be one cause).
    The most configurable layout manager is the GridBagLayout, but may not be easy to use if you haven't tried it before.

  • Tasklist data with components

    Hello Guys,
    I am trying to fetch the task list for headers,operations and components. Since there is no std table to retreive, I end creating query thru SQVI by joining PLMZ,PLPO,STPO to fetch the details. But I am not sure what is the connetivity between these fields to get the info. I tried with various options and no luck.
    I assume these three table will give me the info. if yes, please let me know the sequence of tables and also the link between tables to fetch only the task list associated with components.
    Mahee

    Hi,
    Take table PLMZ.
    Inputs:
    Task list type (PLNTY), Group (PLNNR)
    Get the BOM Category (STLTY) & BOM (STLNR).
    Take table STPO.
    Inputs:
    STLTY & STLNR
    Get IDNRK value MENGE (Quantity) & MEINS (UoM).
    Regards,
    Maheswaran.

  • How to prevent B1 from populating the grid with components?

    Hello group,
    We have customized a form that pops up when user enters a parent item (of a template-type BOM) in the quotation grid.  The form displays the component items and lets the user mark which items to "paste" onto the quotation.  However, B1 automatically populates the grid with the component items once focus moves away from the item code column. 
    <b>How to prevent B1 from populating the grid with components <i>while</i> retaining the parent item in the item code column?</b>  I've tried trapping the Validate event, etc. with no success.

    Instead of setting the parent item up as a template type BOM, you could set up the list of parent/child items on a user table and use this user table to display the items in your pop-up screen.  As the parent item would no longer be a template BOM, Business One would no longer automatically popuplate the grid, and you could write your own code to add only the items selected in your pop-up screen into the grid.
    John.

  • Creating BOM with components but using additional UOM

    Hi,
    I have a requirement.I want to create a BOM using componennts with their additioanl UOMs.
    Example: Parent material ABC123 UOM:EA
    Component : Test001,UOM EA,additional UOM: DZ
    Now if I am creating a BOM for ABC123 with components Test001 but overwritting the default UOM EA with Additional UOM DZ,system throws error 'Unit of measure DZ not supported for material Test001 in plant XXXX'
    I have maintained additional UOM DZ for component in material master.
    Is there any setting in the system which will allow me to use additional unit of measure for the component ?
    Please suggest
    Best Regards,
    manOO

    Hello, and I apologise if my answer is a little late, but all you have to do is maintain the production unit in the 'Work Scheduling' view of MM02.
    In the 'General Data' tab, update the 'Production Unit' field with the UOM which you would like to create the BOM.
    As long as the 'Additional Data' Units of Measure is updated in MM02 for the raw material, this should fix your problem.
    Regards
    Adam

  • Re: Using JScrollPane With JTable

    >
    myNamePane.setVisible(true);This is meaningless, a component becomes visible by default when you add it to a visible container
    if(e.getSource().equals(newStudent))
           JFrame newFrame = new JFrame("Please select a student");
           newFrame.setContentPane(myNamePane);
           newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
           newFrame.setResizable(false);
           newFrame.pack();
           newFrame.setVisible(true);
         }Which brings us to the main issue, you need to add the JScrollPane to you frame
    newFrame.add(myNamePane);Read the tutorial: [Using Top-Level Containers|http://java.sun.com/docs/books/tutorial/uiswing/components/toplevel.html]

    Hello Rodney,
    Thanks for the information and the tutorial.. I've worked with containers before but never got around to reading that one, which has clarified a few things for me.
    Unfortunately however, my problem persists. I obviously can't set the content pane as the JScrollPane and add it to the Frame, so rather than setting the JScrollPane as the content pane (which I did previously), I added it to the frame as you suggested:
    if(e.getSource().equals(newStudent))
         JFrame newFrame = new JFrame("Please select a student");
    //     newFrame.setContentPane(myNamePane);
         newFrame.add(myNamePane);
         newFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
         newFrame.setResizable(false);
         newFrame.pack();
         newFrame.setVisible(true);
    }But the same thing happens! All I see is a new, empty JFrame. I feel like my understanding of the JScrollPane may be flawed, but I'm really not sure :/
    Edit: In fact, it is most definitely a problem either with my JTable or my JScrollPane. I used the setPreferredSize() method to check if the JScrollPane was being displayed in the JFrame, and it is. There is no JTable in the pane however.
    Edit #2: The problem was, in fact, with my JTable. The ResultSet I was using was TYPE_FORWARD_ONLY, and I was trying to call studentNameSet.first(), which prevented the JTable from ever being created. Thanks for your help, Rodney. Although I do have one more question.. Do you know a better way for me to find the number of student names given that ResultSet? I can't iterate through it twice as I had done earlier, so now for testing purposes I've simply hardcoded the number in, but I'd rather have the program find the total number of entries dynamically.
    Edited by: Pheer on Jul 22, 2008 10:07 AM
    Edited by: Pheer on Jul 22, 2008 10:09 AM

  • Highlighting text fieldon focus with components

    Is there a way to highlight a text field when the focus is in that field. I know on a web page you can do this with JS, but wasn't sure about with AS. I am using components also.

    If you just want to highlight one word at a time then you can use:
    textComponent.setSelectionStart(...);
    textComponent.setSelectionEnd(...);
    The above code will use the default selection background/foreground font colours.
    Here is an example of a Find/Replace dialog that uses this approach.
    http://www.discoverteenergy.com/files/FindReplace.java
    If you want to get fancier and use different styles of fonts and colours for different words then you have to use JTextPane which supports StyledDocuments.
    The basic approach is to create attribute sets as follows:
    MutableAttributeSet comment = new SimpleAttributeSet();
    StyleConstants.setForeground(comment, Color.gray);
    StyleConstants.setItalic(comment, true);
    Document doc = textPane.getDocument();Insert new text into the document with the 'comment' attribute:
    doc.insertString( doc.getLength(), "comment text", comment);
    Change the attribute of existing text in the document with the 'comment' attribute:
    doc.setCharacterAttributes( 0, 3, comment, false );
    Here is a simple Java syntax highlighter that uses this approach:
    http://www.discoverteenergy.com/files/SyntaxDocument.java
    Note, most is the above code is devoted to handling multi-line comments. The main highlighting code is in the 'checkForTokens()' method.

  • Is there a simple example, I can see how to connect to a db using Flash 8 and actionscript? (not with components)

    I have been looking all over for a simple "hello world"
    example, on how to connect to a database, and pass a param, and
    return a dataset. I would like one that does not use components.
    (Actionscript only). That uses ColdFusion 7.x and Flash 8. Can
    anyone point me to one?

    Thanks Craig, I saw that example, but it was meant for Flash
    MX, and according to the Flash 8 documentation, the NetServices is
    now deprecated. Anyway, I posted my question on another site and
    some supplied me with a simple example. Here is the url if anyone
    is interested...
    sample

  • Creation of Purchase Req with components in the case of subcontracting

    Hi Frndz,
    We would appreciate if anybody can help up us in this.We are trying to build a Z-functionality to create a purchase requisition for subcontracting material (with special procurement key=30).We are able to create PR with item category "L".But the demand for components are not active.(In the item details of PR-tab:material data-)The TAB "Components" is seen.But on clicking it is not going to the items and the demand is also not created for these items.
    Can anybody tell us which is the standard BAPI for this Or is there any particular field to be passed in FM BAPI_REQUISITION_CREATE?
    Regards,
    Karthick.C

    We needed to do the same. Tried many different BAPIs and FMs, but in the end...
    we BDC'd it. Sorry.

  • Problem with components after action performed

    I am using JPanel in my JApplets and with that I am communicating the data between the my Applets (both r running in same page)I can recv my data but with that I want to add some components to the JPanel . I tried with methods repaint() update(Graphics) . still I can't achive wat I am X-pecting can any of u help me .

    I am told that the correct answer is to call
    revalidate();
    repaint(); Certainly revalidate on its own does not work for me.

  • Creating JScrollPane with vertical scroll only...

    Anyone got any idea how to use a JScrollPane to perform vertical scrolling only?
    The components should be stacked vertically, as wide as the scrollpane and as high as they need to be.
    Is it only possible by adding a ComponentListener to the JScrollPane (or the JViewPort) and setting the maximum width of the components to the width of the viewport?
    Incidentally, anyone know how a JLabel (or any text component) calculates its preferred size when it can wrap the text contained? Ie, how do you get the preferred height for a specified width?

    Doh - implement Scrollable to return true for getScrollableTracksViewportWidth()!

  • Problems to show a Vertical JScrollPane with JList

    I have a JList within a JScrollPane, and update the JList with the output from a process.
    This means that the JList is updated very quickly with a lot of data.
    The scrollpane policy is set using this :
    myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    The problem happens as the list is being updated - sometimes the slider on the scrollbar disappears. It can reappear again, but this behaviour seems completely random.
    This means that if the process completes and the JList stops being updated, the lack of a slider prevents me from reviewing the JList contents.
    Does anyone know why this happens and what I can do to prevent it?

    JList displays the contents of a Vector. The Java version is JDK 1.2.2. And I'm using Windows 2000.

  • Anyone else notice this instance bug with components?

    This seems to affect all components. It seems to work if the
    instance names are left out or if they are both the same. Try this:
    Put a button on frame 1 and a button on frame 2 (it doesn't matter
    if you duplicate the button for frame 2 or add it to a blank
    keyframe). notice the following:
    Results for Flash 9 actionscript 3
    button2 does not show up in correct x,y location but label
    updates correctly
    Results for Flash 9 actionscript 2
    button2 shows up in correct x,y location but with no label
    If the buttons are on separate layers it works fine, could
    someone explain why this is happening (what makes it work if they
    are on different layers and why they don't work if they're on the
    same layer)? I want to use the same instance name so I can
    reference the button but the x,y location of the button doesn't
    change when it should.
    Thanks!

    Yes, I noticed this the other day but didn't make a connection with the US holidays. Odd quirk.

Maybe you are looking for

  • Debilitating X-Fi Fatal1ty Noi

    I've read pages and pages of the "X-Fi Fatalty Popping/crackling noises" thread, altho honestly, not all of it. But here's the thing. Some people on the thread sound like they have my problem, but others talk a lot about faint or rare pops or hisses

  • Cloud business app and document sets

    we have a cloud business app connected to our office 365 tenant when we create an entity we would like to create a document set in a specific document library, is this possible for the created event on the entity or do we need to run a server side ac

  • On change statement problem

    Hi All, I am craeting program for automatic sending mail..... in that program i have write body part with header and line item..... present my output is like below: Controling Area | Cost center | Company Code 5000                | 159040        | 04

  • Apple keyboard media keys not working

    Yesturday i was trying to trun down the volume in my itunes off my apple keyboard, when i went to do so nothing happend even with the eject button with the cd nor can I make the screen brighter or darker and the dashboard key is on my play key.

  • PMS ratings should come in decimals

    Hi Experts, We are implementing the PMS module. I am facing problem in getting the ratings in decimals. There is a formula Whitage*Rating.The resultant has to come in decimals.At present the rating is showing as rounded figure. How to get the rating