Setting size for JPanel to fit JTable

hi!
Iam stuck with some grey area in JPanel or JScroolPanel with holds JTable, starting to get gray hair by trying to get rid of that
public class MiniCalTopPane extends JPanel {
     private static final long serialVersionUID = 8490663735555155912L;
     private TableValues tv;
     private JTable table;
     private JLabel lable;
     public MiniCalTopPane() {
          //create pane with border layout
          super(new BorderLayout());
          //create components
          tv = new TableValues();
          table = new TableW(tv);
          lable = new JLabel("2006");
          lable.setSize(table.getWidth(), 25);
          System.out.println(table.getWidth());
          JScrollPane jsp = new JScrollPane(table);
          jsp.setPreferredSize(new Dimension(200,
                    (table.getHeight())));
          this.add(lable, BorderLayout.BEFORE_FIRST_LINE);
          this.add(jsp, BorderLayout.CENTER);
          setPreferredSize(jsp.getPreferredSize());
          setBackground(Color.GREEN);
          this.setOpaque(true);
}JTable
public class TableW extends JTable{
     private static final long serialVersionUID = 2480280947312015884L;
     private static final int ROW_HEIGHT             = 20;
    private static final int COL_WIDTH              = 20;
     public TableW(TableModel dm) {
          super(dm);
        this.changeSelection(0,0,false,false);
        this.setAutoCreateColumnsFromModel(true);
//      initiate row height
        this.setRowHeight(ROW_HEIGHT);
        this.setAutoResizeMode(AUTO_RESIZE_ALL_COLUMNS);
        this.setRowSelectionAllowed(true);
        this.setColumnSelectionAllowed(true);
        //no dragible colums please!
        this.getTableHeader().setReorderingAllowed(false);
        //dont show grid in table
        this.setShowGrid(false);
        tableHeader.setBackground(Color.WHITE);
          TableColumnModel tcm = this.getColumnModel();       
        //add cutom render to
          for (int i = 0; i < this.getColumnCount(); i++) {
               TableColumn tc = tcm.getColumn(i);
               tc.setCellRenderer(new SmallCallRender());
     }I don't se whats is the proble, hope you can point me out :P
and thanx in advance

Well, the code you posted isn't executable, so we can't tell whats going on based on the code you posted.
Here is a simple example that sizes the frame based on the tables size:
http://forum.java.sun.com/thread.jspa?forumID=57&threadID=627108
If you want the frame to be bigger than the table then you can always add the table to the NORTH of the BorderLayout and set the color of the panel to whatever you want. Or, if you keep the table in the center then you need to set the background of the JViewport of the JScrollPane.
If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
And don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the code retains its original formatting.

Similar Messages

  • Set size of jPanel

    Hi i've create a jForm in netbeans. To this I have added a scrollpane containing a jPanel called PrintPreview. (I have to do this rather than use the automated preview of printUtilities because of some items I need removed from the original jPanel before printing).
    I need to set the size of the PrintPreview jPanel as it's instantiated. I have the dimensions created from another class called "Gbl".
    In the constructor is the following:
    /** Creates new form PrintPreview */
    public PrintPreview() {
    PreviewPanel.setPreferredSize(new Dimension(Gbl.previewWidth,Gbl.previewHeight);
    PreviewPanel.setMaximumSize(new Dimension(Gbl.previewWidth,Gbl.previewHeight);
    PreviewPanel.setMinimumSize(new Dimension(Gbl.previewWidth,Gbl.previewHeight);
    Window.pack();
    initComponents();
    this.setLocationRelativeTo(null);
    // ADD CODE - COLLECT DRAWING FROM ARRAY
    PreviewPanel.repaint();
    I would like the jPanel set to these dimensions however I would also like the scrollPane to remain at it's standard size so I can scroll the diagram as necessary.
    Could you please tell me where I am going wrong? The three setSize lines are flagged as erroneous. The dimensions are int and have tried double.
    Any advice is good...
    Thanks

    Ok I'm going to add onto this thread because it still relates to the original problem. setting size of jPanel.
    Some details first:
    OS - Ubuntu Gutsy 7.10
    Kernel - 2.6.22-14-generic
    NB - v5.5.1
    Java version - java version "1.5.0" / gij (GNU libgcj) version 4.2.1 (Ubuntu 4.2.1-5ubuntu5)
    Research:
    I have been trawling the net for days trying to resolve this but I am struggling to find anything specific to my problem. I keep finding general methods using given NB facilities. I've also scoured a couple of my Java books but of course they're not totally relevant to NetBeans. I've practiced using the forum this afternoon to find things but with my lack of knowledge using both forums and java has left me a little bamboozled. I've been working on this problem for a couple of days now and achieved very little.
    My specific problem is this:
    I have a JFrame GUI. Inside that I have a jTabbedPane containing a jScrollPane containing a jPanel. I would like to have the jPanel display at A4 size relevant to the screen it is displayed on. e.g. I have a separate global class "Gbl" that calculates the dimensions based on current dpi and then creates the necessary measurements to feed to my preferred size function.
    I have tried implementing the preferred size method to the constructor and have also tried adding it to all four ways to enter bespoke code to NetBeans' autogenerated code. (Pre-init, Post-init, Pre-creation and Post-creation code) To no avail. Nothing changes on screen.
    The code I am trying to enter is as follows:
    // Set preferred size of user-drawing-area (jPanel1)
    jPanel1.setPreferredSize(new java.awt.Dimension(600,500));
    jPanel1.setMaximumSize(new java.awt.Dimension(600,500));
    jPanel1.setMinimumSize(new java.awt.Dimension(600,500));
    // Set preferred size of jPanel1 container (jScrollPane1)
    jScrollPane1.setPreferredSize(new java.awt.Dimension(600,500));
    jScrollPane1.setMaximumSize(new java.awt.Dimension(600,500));
    jScrollPane1.setMinimumSize(new java.awt.Dimension(600,500));
    // Set preferred size of the jScrollPane1 container (mainTabView(Tabbed pane))
    mainTabView.setPreferredSize(new java.awt.Dimension(600,500));
    mainTabView.setMaximumSize(new java.awt.Dimension(600,500));
    mainTabView.setMinimumSize(new java.awt.Dimension(600,500));
    I am using absolute values here to omit any error getting the variables from my Global class. If it works I will add them and test again.
    Ideally, I would like the jPanel to be set to an A4 size yet have the containers at a smaller more "screen-manageable" size (With scroll bars). Then if the GUI is maximized, then it only expands to the full size of the A4 sized jPanel if possible.
    Of course, this may not be possible or there may be a far better method for doing this, however I am really stumped. I've had some good advice this afternoon of whihc has opened may eyes some. Although, I have made no headway so far. I hope the above follows site-rules and gives enough information to resolve this issue. I'm losing hair rapidly!
    I'm grateful for any advice given. Thank You

  • Set Maximum size for combobox editor in JTable

    Hi guys.
    I have a JTable with a custom JTextArea as editor for string datatypes.
    On the other hand, I have a combo editor too for some other columns of the table.
    My question is to know whether I can force the combox editor not to grow along with the text area.
    When I have a multiline text in a cell, I don 't want the combo box editor to fill the entire height of the row (the row height is continuously adjusted as user enter text into the text area cell editor), but to remain as big as just to render one line.
    Thanks.

    you know there's a swing forum, why not use it :-)
    As to your problem: the basicUI simply forces all editors to fit the cell size, returning more reasonable max-sizes for the combo wouldn't help. Way out might be to wrap into a panel with an appropriate layoutManager. Not entirely trivial, would expect some work ...
    Cheers
    Jeanette

  • Setting tooltip for columns in a JTable

    Hi!
    I have a JTable inside a JScrollPane. How do I set tooltip for each columnheader of the JTable?
    I have noted that if I don�t have the JTable within the JScrollPane, the columnheaders are not shown.
    Regards
    Johan

    1) You need to set the tooptip text on the renderer for the column (yourTable.getColumnModel().getColumn(...).getHeaderRenderer()).
    2) The header is a separate component to the table. When you add a table to a scroll pane it automatically adds the header to the scroll pane too. You can get the component (yourTable.getTableHeader()) and add it to your own container if you wish.

  • How to set Size for Player

    Hi All,
    Please tell me how to set a size for Player ??
    Here is my implementation...
    //Creating MediaLocator
    mrl = new MediaLocator("vfw://0");
    //creating DataSource
    ds = createDataSource(mrl);
    //creating Realized Player
    player = createRealizedPlayer(ds);
    and i'm getting the player's visual and assigning into one Component..
    when adding the Component into a JFrame it is not with fixed size ??
    I want to know, it is possible to set the size for the Player ?
    Thanks in Advance,
    Karthikeyan R

    James,
    Sorry, I should have read your request more thoroughly. You said you want to make a select list like a multi select. Why do you want to do this? There are various tools used in web development for various reasons and sticking to those standards makes using your application easier for end users.
    Why not just use a select list, Popup LOV, or radio button to present the options?
    Regards,
    Dan
    http://danielmcghan.us
    http://sourceforge.net/projects/tapigen
    http://sourceforge.net/projects/plrecur
    You can reward this reply by marking it as either Helpful or Correct ;-)

  • Maximum size for JPanel in BorderLayout

    I'am using a BorderLayout in my JFrame. I want to place a JPanel in BorderLayout.CENTER. The problem: It should use the maximum possible space.
    For example, if I place a JButton in CENTER, the JButton will grow very big. I want the same behaviour for a JPanel.
    Using setPreferredSize doesn't seem to be a solution because I want the JPanel to resize dynamically, like a JButton does.
    Any ideas? :-)
    Thanks

    The borderlayout is the layout which resizes the components as and when the frame is resized. So i think you should not have a problem like resizing.
    One more thing when u are adding a panel with a borderlayout, do specify where the components are to be added on the panel. i.e. on north, center or south,etc...
    May be this simple example help u out, just copy paste the code and run it.
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Container;
    import java.awt.Dimension;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    public class BorderMain extends JFrame {
    Container c;
    JPanel pnl;
    BorderLayout bl;
    public BorderMain()
         setPreferredSize(new Dimension(200,200));
         c = getContentPane();
         bl = new BorderLayout();
         pnl = new JPanel();
         pnl.setLayout(bl);
         pnl.setBackground(Color.GRAY);
         c.add(pnl);
         c.validate();
         setVisible(true);
         pack();
         public static void main(String[] args) {
              new BorderMain();
    now when u add anythin to the panel just say
    pnl.add(new JButton("OK"), BorderLayout.NORTH);
    pnl.add(new JButton("OK"), BorderLayout.CENTER);
    pnl.add(new JButton("OK"), BorderLayout.SOUTH);
    this is just an example.
    if u add anything only to north, then to the panel will occupy all the space given.
    Regards
    Poonam.
    and if ur adding another panel on a panel with the borderlayout then u need to set the same layoutfor the inner panel also.

  • Cannot set border for JPanel

    I am not able to select any border for a JPanel, except <default>, in the property window of the visual designer. I can insert a statement by hand to get the border (e.g.: jPanel1.setBorder(new javax.swing.border.EtchedBorder());
    ), but I would like to do it with the visual designer. Is this a missing feature or do I do something wrong?
    Thank you
    Heinz

    You first have to make a Border object in your source code, then it will allow you to select the border.
    example:
    import javax.swing.border.*;
    public class MyFrame1
    // Create a border object in your class
    // Add this next line, and change it to
    // create the type of border you want.
    Border borderPanel1 = BorderFactory.createEtchedBorder();
    after this, you can use the inspector to set the border property (you should see borderPanel1 in the combobox of choices)
    Take Care,
    Rob
    null

  • How do I set size for Facebook export?

    I was recently contacted by a potential client regarding some images from an event I covered.  I had loaded some images to Facebook using the Facebook loader button, thus creating an album online.  I went to look at the album, and it allowed me to download the image.  The image size far exceeded the resolution I place on the web (2048 x 13xx) and would allow a client to simply download the image and print the image (5.6" x 8.5" @240dpi) as often as they want.
    I'd like to set the uploaded size to 600 x 400 pixels, in order to limit the size image that can be downloaded and printed.  How do I go about this, or do I simply have to export to a folder, THEN upload from the folder to Facebook?

    See:
    https://discussions.apple.com/message/15135282#15135282
    I believe Aperture is automatically resizing the uploads for Facebook to stay within specs, going through an optimization procedure.  That procedure may be more focused on file size via the compression setting, so the number of pixels may not be as altered as you may expect or desire.  I don't know any control that you can exercise via the Share command.  Nothing other than exporting first to a folder.
    Ernie

  • Setting size to JPanels

    Hi
    A small niggly problem with JPanels but I can not seem to solve it, Can anyone please tell me how to control West Panel size ? I've tried thiswestPanel.setPreferredSize(new Dimension(200, 500)); it only controls the width of it but NOT the length. I want West JPanel to go right down to page so the South JPanel can be side of it and not below.
    Thanks
    Zed

    Caarmel wrote:
    It should work.Insufficient detail to come to that conclusion. Apart from which, anything that should work usually does.
    I'm guessing too, but BorderLayout isn't designed to provide the layout that the OP evidently wants. The layout it does provide is adequately described and illustrated in the API.
    Nesting two containers both having BorderLayout, with the inner container using NORTH, CENTER and SOUTH added to the outer container at CENTER with the remaining parts at EAST and WEST may fit the bill.
    db

  • Setting background for single row in JTable

    Hi,
    I have a table which uses the DefaultCellRenderer for cols0,1,3-5
    while column 2 uses a custom renderer.
    When user right clicks mouse on one of the rows i get the rowindex and colindex selected and tries to set background color for this row. but the whole table get painted(of course except 2nd column)...rather i need just the row to be colored.....any solution is greatly appreciated.the code is below....
    int rowIndex=table.rowAtPoint(p);
         int colIndex = table.columnAtPoint(p);           
         for (int i = 0; i < 6; i++) {                    
              if (i!=2){
                   DefaultTableCellRenderer r = (DefaultTableCellRenderer) table.getCellRenderer(rowIndex,i);
                   Component c = taskListTbl.prepareRenderer(r, rowIndex, i);
    c.setBackground(Color.yellow);
              }

    Maybe my reply in this posting will help:
    http://forum.java.sun.com/thread.jspa?forumID=57&messageID=1730267

  • Set size for JScrollPane

    I have a JLabel that I am using to display images thri ImageIcon. i want to wrap the jlabel in a JScrollpane so that i can view the entire image by scrolling. i did this part but the scroll pane is extremely small to begin with. how can set the size of the Jlabel initially ??

    You don't set the size of the Label, you set the size of the
    ScrollPanel. Also you don't add/place the Label on the Frame/Panel,
    you add the ScrollPanel to the Frame/Panel.
    The Label will take on the size of the Image you load into it.

  • Circular and oval cropping at set size and resolution?

    I know how to use the M tool to create circles and ovals and i know you can set that to certain dimensions, but that doesn't do everything I need.
    How do you crop circles and ovals out of a photo, at a set size (for example, a 1 inch circle ) at a set resolution for printing?  What I need to do is crop circular and oval images out of a photo, say at 250 dpi, then paste them onto a blank white page for printing.
    So if I've got let's say a photo that's 14x10 inches at 300dpi, I want to be able to go in, crop out an oval or circle, with as much or as little of the photo that I can or want to, setting that automatically to a certain dimension and dpi, then paste it into a blank white page I've already created at that same d
    When finished I'd have maybe 20 or 30 images on a page that I can flatten all the layers and print.
    I can't find a way to set size and resolution with anything other than the regular square crop tool.

    You can make an action and use it as one step automation to achieve that on an initial selection.
    Step by step instructions:
    With the Elliptical Marquee Tool, make the desired selection on a image.
    Open the Actions panel (Window > Actions (Alt+F9), from its menu at the top right or corresponding buttons at the bottom, choose New Action, and in the dialog that appears press the Record button.
    From the Image menu, choose Crop.
    From the Selection menu, choose Inverse (Ctrl+Shift+I)
    Press the d key on your keyboard to reset the foreground/background color swatches.
    Press Ctrl + Delete keys on your keyboard to fill with white.
    From the Image menu, choose Image Size (Ctrl+Alt+I), make sure the Resample Image is checked, and in the Document Size section enter the desired dimensions and resolution and press OK.
    In the Actions Panel press the Stop Recording button.
    Now you can copy or drag the image to another image.
    For the next image make the oval selection, go to the Actions panel, select the actions you created above, and press the play button. You can also create a keyboard shortcut in the action's property accessible by double clicking the action.
    The creation of this action assumes that in the final image you will be composing oval images on white background without overlapping their rectangular bounding boxes. If you plan to overlap them then the action must be modified to make the image a transparent layer and delete outside the oval instead of filling with white.

  • I want to set a maximum size for pictures when FF shows websites. How can i do that? NO I DONT MEAN "HOW TO ZOOM".

    I have FF 34 but this problem has been there for a lot of earlier versions. On many webpages there are pictures that cover my whole screen, and I want to set maximum size for showing images on webpages.
    I ONLY wanr to change the maximum size of the images, AND IAM NOT asking about how to zoom the webpage.

    Do you want to hide large images or merely make them smaller by setting a max-width and max-height?
    You would probably have to use JavaScript (bookmarklet) to achieve this reliably.
    There are bookmarklets to make large images fit in the window to avoid a horizontal scroll bar
    You can try this code in the <b>userContent.css</b> file (adjust the max-width accordingly).
    *http://kb.mozillazine.org/userContent.css
    <pre><nowiki>img { max-width: 1024px !important; height: auto !important; }</nowiki></pre>
    The customization files userChrome.css (user interface) and userContent.css (websites) are located in the <b>chrome</b> folder in the Firefox profile folder.
    *http://kb.mozillazine.org/Editing_configuration
    *Create the chrome folder (lowercase) in the <xxxxxxxx>.default profile folder if this folder doesn't exist
    *Use a plain text editor like Notepad to create a (new) userContent.css file in the chrome folder (file name is case sensitive)
    *Paste the code in the userContent.css file in the editor window
    *Make sure that you select "All files" and not "Text files" when you save the file via "Save file as" in the text editor as userContent.css.<br>Otherwise Windows may add a hidden .txt file extension and you end up with a not working userContent.css.txt file

  • How to set an empty JPanel to maximum size?

    Hello!
    I created class extends JFrame.
    I want this maximum size so I set the minimum size as screen size:
    setSize(screenWidth,screenHeight);
    Now I added an empty JPanel,
    and I want it to be the maximum size.
    But the problem is - I don't know what is the maximum of the current size without the frame borders. I mean, after set it to maximum size (I don't know how),
    I could get the width and height of the current size without the frame borders by:
    frame.getContentPane().getSize();
    In conclusion, I want to set an empty JPanel to maximum size and get JFrame size without the frame borders.
    Thanks!

    800512 wrote:
    Now I added an empty JPanel,
    and I want it to be the maximum size.Define "maximum size". You want it to fill the screen or you want it to be the maximum size inside its container (JFrame in this case)?
    You cannot make a component break out of its container, that's for sure. So assuming you want the component to grow to the maximum size inside its container, that should already happen when you add the component to the CENTER position of the JFrame's container. By default it has a BorderLayout.

  • Set specific size for JTextfield/Jbutton in BorderLayout?

    can some one tell me how to set a specific size for JTextfield/JButton in Border/BoxLayout please?
    I stried setSize, setPrefersize, setMAxsize, setMinsize, setBounds... but it won't work?
    For example. If I add a jbutton to a jpanel, which has borderlayout, it will take up ALL the space in that jpanel.
    Thanks

    Typically you use a BorderLayout for the high level layout and then add panels using other layouts to the BorderLayout. So for example on a simple dialog that is using a form that asks your for your first name and last name you would build a panel with those fields and add that panel to the center of the BorderLayout. Then you would create another panel for the "Ok" and "Cancel" buttons which would typically use a FlowLayout. Then you add that panel to the South of the BorderLayout.
    The Swing tutorial on [url http://java.sun.com/docs/books/tutorial/uiswing/layout/visual.html]How to Use LayoutManagers has all the information you need to know on using layout managers.

Maybe you are looking for

  • K330 Video card upgrade question.

    New to forum and was just about to pull the trigger on a new K330-77471CU (from BB). However, I read a customers comment saying that this unit only had an AGP port, no PCI express slots for upgrading the video card, can this be true??? Does'nt seem p

  • Purchase Requisition workflow escalation

    Hi All, I need help with purchase requisition workflow escalation. The workflow for the requisition escalate to the next level if not approved within 24 hours.So i dont want the workflow to escalate on weekend. I want to know what can i do. Tx Rosi

  • Selected Values not displaying in Multiselect Prompt

    Hi all, We are having reports with Multiselect Prompts. When we select values , we are unable to see the corresponding values. Is their any rule like Multiselect Prompt won't work if there are Null values in it..

  • CS6 does not see my GPU. It did and now not.

    Hi CS6 stopped seeing my GPU. I noticed the problem when trying to do one of Deke's 3D tutes on on lynda.com. So I was able to do most things till I tried 3D. In cs5.1 can see it and allows my to activate it. I recently uninstalled CS5.1. I reinstall

  • Photoshop Elements Organizer Iphoto

    I've used Photoshop Elements (3.0) Organizer for about a year, and I have inserted Notes on a lot of my pictures, which I assume is similar to the Comments section of iphoto. Is there any way (besides retyping/copying/pasting) to get those Notes into