Shape a JPanel based on the components added

Can I shape the JPanel depending on the components added to it?
Please refer the code I have posted in http://forums.sun.com/thread.jspa?threadID=5323662&messageID=10386358#10386358
My requirement is that, I need to shape the JPanel(mainPanel) such that the icon and label are the borders.
Rony

Please read up on using Layout Managers in the Swing tutorials.

Similar Messages

  • How to change the components in a visible JPanel?

    How to change the components in a visible JPanel?
    Is there any way to change the components in a JPanel while it is already visible in a JFrame? I tried the na�ve approach of removing the components and adding new ones, but the effect is not the expected.
    For now I'm opening new frames with newly created panels.

    After adding/removing components to/from a panel try:
    panel.revalidate();
    panel.repaint() // sometimes this is also needed, I'm
    not sure whyI'm not certain, but I think that panel.revalidate() implicitly calls repaint() only if something actually changed in the layout. If nothing changed, it sees no reason to repaint; hence, if something changed in appearance but not in layout, you have to repaint it yourself.
    Or something like that. I'm no expert. ;)

  • Auto-resize the components of JTabbedPane with JPanels

    Hi,
    We have swing window with tabbed pane having two JPanels. There are couple of components (button/text
    fields/JXTable/Jtree ..etc)added to each panel. so far, every thing is working fine.
    Issue is, when we try to expand the winodw size, the components of each panel are static. The size of components
    are not changing accorning to window size. All the components are center alligned with increasing the window size. It would be great help, if you can help on this.
    Following is the sample code used to prepare  swing window.
    public class SOS extends JFrame implements TreeWillExpandListener,
                                               TreeExpansionListener,
        JPanel firstPanel = new JPanel(new GridBagLayout());
        JPanel secondPanel = new JPanel(new GridBagLayout());
        public SOS() throws SQLException, ParserConfigurationException,
                            SAXException, IOException, XPathExpressionException {
            //EHDD Tabbed Pane
            nehObjectTypelist = new JList((createObjectsListData()).toArray());
            nehObjectTypelist.setFont(font);
            nehObjectTypelist.setCellRenderer(new CheckListRenderer());
            nehObjectTypelist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            nehObjectTypelist.setBorder(new EmptyBorder(0, 4, 0, 0));
            nehObjectTypelist.addMouseListener(new MouseAdapter() {
            JScrollPane nehObjTypeSP = new JScrollPane(nehObjectTypelist);
            nehObjTypeSP.setSize(200, 200);
            nehOwmerslist = new JList((createOwnersListData()).toArray());
            nehOwmerslist.setFont(font);
            nehOwmerslist.setCellRenderer(new CheckListRenderer());
            nehOwmerslist.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
            nehOwmerslist.setBorder(new EmptyBorder(0, 4, 0, 0));
            nehOwmerslist.addMouseListener(new MouseAdapter() {
            JScrollPane sp = new JScrollPane(nehOwmerslist);
            sp.setSize(200, 200);
            //JTree with checkbox
            DefaultMutableTreeNode root = createFirstLevel();
            final DefaultTreeModel model = new DefaultTreeModel(root);
            nehTree = new JTree(root);
            QuestionCellRenderer renderer = new QuestionCellRenderer();
            nehTree.setCellRenderer(renderer);
            QuestionCellEditor editor = new QuestionCellEditor();
            nehTree.setCellEditor(editor);
            nehTree.setEditable(true);
            nehTree.addTreeWillExpandListener(this);
            nehTree.setShowsRootHandles(true);
            nehTree.setModel(model);
            nehTree.getSelectionModel().setSelectionMode(TreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
            JScrollPane scroll = new JScrollPane(nehTree);
            scroll.setPreferredSize(new Dimension(200, 180));
            scroll.setFont(font);
            GridBagConstraints gbc = new GridBagConstraints();
            gbc.insets = new Insets(1, 1, 1, 1);
            gbc.gridx = 0;
            gbc.gridy = 0;
            //gbc.gridwidth = 2;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            //gbc.anchor = GridBagConstraints.LINE_START;
            JLabel nehHeading =
                new JLabel("Select your criteria and click the Fetch Topics by Criteria button");
            nehHeading.setFont(font);
            firstPanel.add(nehHeading, gbc);
            gbc.insets = new Insets(1, 1, 1, 1);
            gbc.fill = GridBagConstraints.HORIZONTAL;
            gbc.gridx = 0;
            gbc.gridy = 1;
            gbc.gridwidth = 1;
            JLabel nehDocType = new JLabel("Type");
            nehDocType.setFont(font);
            firstPanel.add(nehDocType, gbc);
            gbc.gridx = 1;
            gbc.gridy = 1;
            JLabel nehDocOwner = new JLabel("Owner");
            nehDocOwner.setFont(font);
            firstPanel.add(nehDocOwner, gbc);
            gbc.gridx = 2;
            gbc.gridy = 1;
            JLabel nehProdTree = new JLabel("Tree");
            nehProdTree.setFont(font);
            firstPanel.add(nehProdTree, gbc);
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridx = 0;
            gbc.gridy = 2;
            firstPanel.add(nehObjTypeSP, gbc);
            gbc.gridx = 1;
            gbc.gridy = 2;
            firstPanel.add(sp, gbc);
            gbc.gridx = 2;
            gbc.gridy = 2;
            firstPanel.add(scroll, gbc);
            gbc.fill = GridBagConstraints.VERTICAL;
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.weightx = 0;
            gbc.weighty = 0;
            gbc.gridheight = 1;
            gbc.gridheight = 1;
            gbc.gridx = 0;
            gbc.gridy = 21;
            JButton fetchButton = new JButton("Fetch");
            fetchButton.setFont(font);
            fetchButton.setSize(new Dimension(175, 35));
            firstPanel.add(fetchButton, gbc);
            fetchButton.addActionListener(new ActionListener() {
            gbc.gridx = 0;
            gbc.gridy = 22;
            JLabel nehOR = new JLabel("- OR -");
            nehOR.setFont(font);
            firstPanel.add(nehOR, gbc);
            JButton searchButton = new JButton("Fetch by Title");
            searchButton.setToolTipText("Enter title search criteria");
            searchButton.setFont(font);
            gbc.gridheight = 1;
            gbc.gridx = 0;
            gbc.gridy = 23;
            gbc.anchor = GridBagConstraints.LINE_START;
            JLabel nehOpenBySVNIdLabel = new JLabel("Open by ID");
            nehOpenBySVNIdLabel.setFont(font);
            firstPanel.add(nehOpenBySVNIdLabel, gbc);
            gbc.gridheight = 1;
            gbc.gridx = 1;
            gbc.gridy = 23;
            gbc.anchor = GridBagConstraints.WEST;
            findTextField.setColumns(20);
            firstPanel.add(findTextField, gbc);
            gbc.gridheight = 1;
            gbc.gridx = 2;
            gbc.gridy = 23;
            gbc.anchor = GridBagConstraints.WEST;
            JButton openButton = new JButton("Open");
            openButton.setFont(font);
            openButton.setPreferredSize(searchButton.getPreferredSize());
            System.out.println("Button Size" + openButton.getSize());
            firstPanel.add(openButton, gbc);
            openButton.addActionListener(new ActionListener() {
            gbc.gridheight = 1;
            gbc.gridx = 0;
            gbc.gridy = 24;
            gbc.anchor = GridBagConstraints.LINE_START;
            JLabel searchLabel =
                new JLabel("Search the repository by title word(s)");
            searchLabel.setToolTipText("Enter title search criteria");
            searchLabel.setFont(font);
            firstPanel.add(searchLabel, gbc);
            gbc.gridheight = 1;
            gbc.gridx = 1;
            gbc.gridy = 24;
            gbc.anchor = GridBagConstraints.WEST;
            searchTextField = new JTextField("", 20);
            searchTextField.setColumns(20);
            searchTextField.setEditable(true);
            firstPanel.add(searchTextField, gbc);
            gbc.gridheight = 1;
            gbc.gridx = 2;
            gbc.gridy = 24;
            gbc.anchor = GridBagConstraints.WEST;
            firstPanel.add(searchButton, gbc);
            searchButton.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
            gbc.anchor = GridBagConstraints.FIRST_LINE_START;
            gbc.gridwidth = 4;
            gbc.gridx = 0;
            gbc.gridy = 28;
            gbc.fill = GridBagConstraints.HORIZONTAL;
            tableScrollPane.setPreferredSize(new Dimension(200, 200));
            firstPanel.add(tableScrollPane, gbc);
            gbc.fill = GridBagConstraints.NONE;
            gbc.gridheight = 1;
            JRadioButton reviewButton = new JRadioButton("Review");
            reviewButton.setFont(font);
            reviewButton.setMnemonic(KeyEvent.VK_B);
            reviewButton.setSelected(true);
            JRadioButton testButton = new JRadioButton("Test");
            testButton.setFont(font);
            testButton.setMnemonic(KeyEvent.VK_B);
            JRadioButton prodButton = new JRadioButton("Production");
            prodButton.setFont(font);
            prodButton.setMnemonic(KeyEvent.VK_B);
            nehGroup.add(reviewButton);
            nehGroup.add(testButton);
            nehGroup.add(prodButton);
            gbc.gridx = 2;
            gbc.gridy = 30;
            firstPanel.add(reviewButton, gbc);
            gbc.gridx = 2;
            gbc.gridy = 31;
            firstPanel.add(testButton, gbc);
            gbc.gridx = 2;
            gbc.gridy = 32;
            firstPanel.add(prodButton, gbc);
            gbc.gridx = 2;
            gbc.gridy = 33;
            JButton printButton = new JButton("Print");
            printButton.setFont(font);
            firstPanel.add(printButton, gbc);
            printButton.addActionListener(new ActionListener() {
            gbc.fill = GridBagConstraints.NORTHEAST;
            gbc.gridx = 0;
            gbc.gridy = 30;
            JButton openTopicsButton = new JButton("Open Selection");
            openTopicsButton.setFont(font);
            firstPanel.add(openTopicsButton, gbc);
            openTopicsButton.addActionListener(new ActionListener() {
            gbc.gridx = 0;
            gbc.gridy = 32;
            JButton mapLinks = new JButton("Insert");
            mapLinks.setFont(font);
            JButton relatedLinks = new JButton("Insert Links");
            relatedLinks.setFont(font);
            relatedLinks.setPreferredSize(mapLinks.getPreferredSize());
            firstPanel.add(relatedLinks, gbc);
            relatedLinks.addActionListener(new ActionListener() {
            gbc.gridx = 0;
            gbc.gridy = 33;
            firstPanel.add(mapLinks, gbc);
            mapLinks.addActionListener(new ActionListener() {
            tabbedPane.add("NEH", firstPanel);
            //NEH Tabbed Pane
            tabbedPane.add("EHDD", secondPanel);
            add(tabbedPane);
            tabbedPane.addChangeListener(new ChangeListener() {
        public static void main(String[] args) throws SQLException,
                                                      ParserConfigurationException,
                                                      SAXException, IOException,
                                                      XPathExpressionException {
            SOS sos = new SOS();
            sos.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
            sos.setTitle("SOS");
            sos.setSize(760, 680);
            sos.setVisible(true);
            sos.toFront();
            sos.setMinimumSize(new Dimension(760, 680));
    Thanks,
    MSR.

    I never use GridBagLayout.
    I suggest that you change to combinations of BorderLayout, GridLayout (without "Bag"!) and GroupLayout.
    bye
    TPD

  • How to create a shape based on the shape of an image

    I want to erase a portion of a mask based on the shape of an image. how can i do this? btw how to create a circle? thx

    Both your questions leave room for imagining what you might really mean, but here's a shot at answering them.
    If you have a mask that you want to erase portions of based on an image... assuming the mask is a simple rectangle you drew with the rectangle tool, change the opacity of the rectangle's fill in the color panel to make it see-thru, place the mask over the image, and using the eraser tool, erase the portions of the mask that you do not intend to retain using the image below it as a guide.
    As for drawing a circle, hover over the rectangle tool and a menu should appear.  Select the oval/ellipse tool.  To draw a circle, hold down the shift key and draw just as you did for the rectangle.  The shift key forces it to retain equal width and height.

  • How can I disable all the components in a JPanel?

    I want to disable all the components( button, text field ) in a JPanel. I know I can search the panel and disable each of its children component recursively. Is there a better way to do this?

    I want to disable all the components( button, text field ) in a JPanel.You haven't defined what you mean by "disable".
    If you mean you want the component to be repainted in its disabled state, then you would need to set the property of each individual component to disable, which would imply some kind of recursion.
    If you just want to prevent components from receiving key events and mouse events, then you can use a glass pane or maybe a panel with an overlay layout that contains a non-opaque panel that intercepts all events.

  • Does adding a field to a table affect a data block based on the table?

    If I make a change to a table like adding a field does it affect data data blocks based on the table?

    The other place I have seen where adding a new column to a table causes problems is when a programmer codes: Select * from table.
    If that is coded in a form, the form will need to be recompiled before it will work properly.

  • Adding Multiple files to many Sharepoint Sites based on the Sites Code (Splitting the data using a code)

    Hi,
    I'm pretty new to Sharepoint and wanted to ask a question to see if it can actually do what we need it to do.
    We would have a top Site within a collection and under this we would have 400 sites for different sections of the business (External) Lots of teams create documents for all these sites and use the Code of the site in each document so we know what business
    site its going to. For example 67890_BusinessReportMay.docx We know this document should be heading to site 67890 
    We have lots of services sending data to these 400 business sites. If we were to do them manually it would take most of our time to go to each site and upload the documents, even if we could do all the sites documents in 1 multiple upload. We still have
    to go to each site to do it
    Is there an easy answer to this? At present I have folders to match each of the 400 Sharepoint Sites and I use an Integration Services package to move all the documents into these 400 Matching folders. I do this using the Code at the start of each file name.
    If it doesn't have a code its put into an error folder and reported back on.
    Then I want something to automatically go through each of these folders and load them into the Sharepoint Sites document libraries. 
    OR
    Say you have 600 files all going to the 500 sites on Sharepoint in one folder. The File contains meta data regarding the Sites Code.  Using this you can split the files and automatically pull them across to the Sharepoint Sites without having to go
    into each Sharepoint Site?
    I'm thinking that you cant do this and I'm hoping I'm wrong. Any help would be greatly appreciated.  
    Debbie

    Hi Debbie,
    According to your description, my understanding is that you want to move the documents to different sites based on the code in the name of the files.
    I recommend to create workflow and set the workflow to start when an item is created to achieve this goal.
    As there is no built-in action which can move the documents cross site, we need to use the custom activity 'Copy List Item Extended' which need to be downloaded from
    http://spdactivities.codeplex.com/.
    Please per the steps in the link below to deploy the custom activity to SharePoint:
    http://social.technet.microsoft.com/Forums/en-US/82609160-152f-461a-9a19-0e996f5a309b/sharepoint-2010-archiving-the-files-from-one-document-library-to-another-document-library-in
    After that, we can create a workflow to meet the need.
    Here is the detailed steps to create the workflow:
    Create a column in single line of text type(called NO for example) in the library where the documents are uploaded, and input value manually in the column to store the code when uploading the documents. (We can also use workflow to extract the code from
    the name of the documents if the codes are always 5 numbers.)
    Create a workflow associated with the library and set the workflow to start when an item is created.
    Select If current item field equals value, change the settings to be If Current Item: NO equals 67890.
    Select Copy List Item Extended, change the settings to be Copy item in Current Item to list at site 67890 URL.
    Select Delete Item, change the settings to be Delete Item in Current Item.
    Create other conditions from step 3 to step 5 to copy the documents to different sites and delete current documents.
    Best regards.
    Thanks
    Victoria Xia
    TechNet Community Support

  • Exit for changing Components in ME21N based on the production Order

    Hi,
          I have a scenerio in which, while creating PO in ME21N for subcontracting(Item category 'L') against a PR, the components for the material should come with my own logic i.e. it will have its production order number, with this production number i will get material of production order. Now i will get the BOM of this material and want to fill the next screen with the same BOM components. So please can anybody help me out how to work out for this problem. I looked for user exit and BADI but was not able to find anything, or is there some other way to do it. Help will be highly appreciated.
    Thanks and regards,
    Pankaj

    Hi,
                 Anybody having any idea. Plz help with your ideas if it is possible to do or not.
    regards,
    Pankaj

  • Illustrator Shape Builder Tool:  After the latest CC update, the tool alters shapes once edited instead of just removing/adding the desired shape.  Anyone else run into this and/or have any fixes?

    I am using a PC and installed the latest update of all the CC programs I use (AI, PS, AE, etc.) and within Illustrator I've noticed the Shape Builder Tool doesn't behave exactly as it did in the past. (And not in a good way.)
    Previous versions allowed me to edit/add/remove shapes from one another without issue (leaving all shape paths as they were before the editing while making the desired alterations), but the newest behavior seems to alter existing paths once shapes are merged/deleted making the tool almost non-usable. 
    Not sure if there's a check box I'm missing or what, but have done some brief research on the problem and haven't found anything helpful.  If anyone has run into this issue and/or knows a way to correct it, I would greatly appreciate it
    Thanks!

    Please show a screenshot before and after.

  • An Image JPanel, A semi-transparent JPanel, and non-opaque components

    This is a more intelligent re-asking of the question I posed here: http://forum.java.sun.com/thread.jspa?threadID=579298&tstart=50.
    I have a class called ImagePane, which is basically a JPanel with an image background. The code is much like the ImagePanel posted by camickr, discussed in this topic: http://forum.java.sun.com/thread.jspa?forumID=57&threadID=316074 (except mine only draws the image, it does not tile or scale it).
    On top of my ImagePane, I can place another component, TransparentContainer. This again extends JPanel, only a color is specified in the constructor, and it is drawn at about 70% opacity. This component is meant to help increase the readability of text components that blend with the background image, without blocking out the background image completely.
    This works very well, until I need to add a component, like, say, a non-opaque JRadioButton in a ButtonGroup. When you select a new JRadioButton at runtime, the semi-transparent JPanel fills with a combination of a completely opaque color (the one specifies to the TransparentContainer) and garbage from the non-opaque component being redrawn.
    I have noticed that the UI is restored to being non-messed up if you place another application window on top of it and then move it. So apparently, one solution is to redraw the entire UI, or just the part that has the JRadioButton on it, every time the radio button is clicked. However, this seems unnecessarily complicated. It seems to me that I am missing something in my TransparentContainer's paintComponent() method. Does anyone have any ideas?
    Here is my TransparentContainer code, if it will help:
    import java.awt.AlphaComposite;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import javax.swing.JPanel;
    public final class TransparentContainer extends JPanel
         /* Private Fields: For use only by this class.
          *  These fields hold information needed by more
          *  than one method of this class.
         private boolean fullTransparencyEnabled;
         private Color baseColor;
         private Color outerBorderColor;
         private Color innerBorderColor;
         private int obw;
         private int ibw;
         private int cbw;
         /* -- START OF METHODS -- */
         /* public TransparentContainer(Color color, boolean fullTrans)
          *   Initiallizes the transparent container object
          *   with 'color' as its base color.
         public TransparentContainer(Color color, boolean fullTrans)
              fullTransparencyEnabled = fullTrans;
              baseColor = color;
              Color borders[] = findBorderColors();
              outerBorderColor = borders[0];
              innerBorderColor = borders[1];
              obw = 3;
              ibw = 1;
              cbw = obw + ibw;
         /* private Color[] findBorderColors(Color base)
          *   Calculates the colors for the outer and inner
          *   borders of the object based on the base color.
         private Color[] findBorderColors()
              Color borders[] = new Color[2];
              int colorData[] = new int[9];
              colorData[0] = getBaseColor().getRed();
              colorData[1] = getBaseColor().getGreen();
              colorData[2] = getBaseColor().getBlue();
              colorData[3] = colorData[0] - 50;          // outerBorder red
              colorData[4] = colorData[1] - 45;          // outerBorder green
              colorData[5] = colorData[2] - 35;          // outerBorder blue
              colorData[6] = colorData[0] + 30;          // innerBorder red
              colorData[7] = colorData[1] + 30;          // innerBorder green
              colorData[8] = colorData[2] + 20;          // innerBorder blue
              /* Make sure the new color data is not out of bounds: */
              for (int i = 3; i < colorData.length; i++)
                   if (colorData[i] > 255)
                        colorData[i] = 255;
                   else if (colorData[i] < 0)
                        colorData[i] = 0;
              borders[0] = new Color(colorData[3], colorData[4], colorData[5]);
              borders[1] = new Color(colorData[6], colorData[7], colorData[8]);
              return borders;
         /* public Color getBaseColor()
          *   Returns the baseColor of this object.
         public Color getBaseColor()
              return baseColor;
         /* public Color getOuterColor()
          *   Returns the outerBorderColor of this object.
         public Color getOuterColor()
              return outerBorderColor;
         /* public Color getInnerColor()
          *   Returns the innerBorderColor of this object.
         public Color getInnerColor()
              return innerBorderColor;
         /* public boolean getFullTransEnabled()
          *   Returns whether or not this object will render
          *   with all of its transparency effects.
         public boolean getFullTransEnabled()
              return fullTransparencyEnabled;
         /* protected void paintComponent(Graphics g)
          *   Paints the component with the borders and colors
          *   that were set up in above methods.
         protected void paintComponent(Graphics g)
              Graphics2D g2d = (Graphics2D) g;
              AlphaComposite alphaComp;
              g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
              g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                                            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
              g2d.setColor(getBaseColor());
              /* Draw the main body of the component */
              if (getFullTransEnabled())
                   alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
                   g2d.setComposite(alphaComp);
              else
                   alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
                   g2d.setComposite(alphaComp);
              g2d.fillRect(cbw, cbw, super.getWidth() - 2 * cbw, super.getHeight() - 2 * cbw);
              alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
              g2d.setComposite(alphaComp);
              /* Draw the inner border: */
              g2d.setColor(getInnerColor());
              g2d.fillRect(obw, obw, ibw, super.getHeight() - obw * 2); // left border
              g2d.fillRect(obw, obw, super.getWidth() - obw, ibw); // top border
              g2d.fillRect(super.getWidth() - cbw, obw, ibw, super.getHeight() - obw * 2); // right border
              g2d.fillRect(obw, super.getHeight() - cbw, super.getWidth() - obw * 2, ibw); // bottom border
              /* Draw the outer border: */
              g2d.setColor(getOuterColor());
              g2d.fillRect(0, 0, obw, super.getHeight()); // left border
              g2d.fillRect(0, 0, super.getWidth() + obw, obw); // top border
              g2d.fillRect(super.getWidth() - obw, 0, obw, super.getHeight()); // right border
              g2d.fillRect(0, super.getHeight() - obw, super.getWidth(), obw); // bottom border
              alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
              g2d.setComposite(alphaComp);
              g2d.dispose();
    }

    I added the main method to your TransparentContainer class ...
         public static void main(String[] args) {
              JFrame f = new JFrame("test transparent container");
              f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              TransparentContainer tc = new TransparentContainer(Color.RED, true);
              JLabel label = new JLabel("Hello, World!");
              tc.add(label);
              f.getContentPane().add(tc);
              f.setSize(800, 600);
              f.setVisible(true);
         }...using the code you posted the label was not shown. I modified your paintComponent(Graphics g) method and I did this (see the areas in bold):
         /* protected void paintComponent(Graphics g)
          *   Paints the component with the borders and colors
          *   that were set up in above methods.
         protected void paintComponent(Graphics g)
              // Call super so components added to this panel are visible
              super.paintComponent(g);
              Graphics2D g2d = (Graphics2D) g;
              AlphaComposite alphaComp;
              g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
              g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
              g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION,
                                            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
              g2d.setColor(getBaseColor());
              /* Draw the main body of the component */
              if (getFullTransEnabled())
                   alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
                   g2d.setComposite(alphaComp);
              else
                   alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
                   g2d.setComposite(alphaComp);
              g2d.fillRect(cbw, cbw, super.getWidth() - 2 * cbw, super.getHeight() - 2 * cbw);
              alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.6f);
              g2d.setComposite(alphaComp);
              /* Draw the inner border: */
              g2d.setColor(getInnerColor());
              g2d.fillRect(obw, obw, ibw, super.getHeight() - obw * 2); // left border
              g2d.fillRect(obw, obw, super.getWidth() - obw, ibw); // top border
              g2d.fillRect(super.getWidth() - cbw, obw, ibw, super.getHeight() - obw * 2); // right border
              g2d.fillRect(obw, super.getHeight() - cbw, super.getWidth() - obw * 2, ibw); // bottom border
              /* Draw the outer border: */
              g2d.setColor(getOuterColor());
              g2d.fillRect(0, 0, obw, super.getHeight()); // left border
              g2d.fillRect(0, 0, super.getWidth() + obw, obw); // top border
              g2d.fillRect(super.getWidth() - obw, 0, obw, super.getHeight()); // right border
              g2d.fillRect(0, super.getHeight() - obw, super.getWidth(), obw); // bottom border
              alphaComp = AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f);
              g2d.setComposite(alphaComp);
              // Do not dispose the graphics
              // g2d.dispose();          
         }...seems to work fine now. Perhaps you should also add methods or additional constructors so the user can easily change the transparency level...and add some javadoc comments to your constructors ...at a first glance I did not know what fullTrans was
    public TransparentContainer(Color color, boolean fullTrans)good luck!!

  • How to Create a Table Component Dynamically based on the Need

    Hello all,
    I have a problem i need to create dynamically tables based on the no of records in the database. How can i create the table object using java code.
    Please help.

    Winston's blog will probably be helpful:
    How to create a table component dynamically:
    http://blogs.sun.com/roller/page/winston?entry=creating_dynamic_table
    Adding components to a dynamically created table
    http://blogs.sun.com/roller/page/winston?entry=dynamic_button_table
    Lark
    Creator Team

  • Two LOVs in same UIX page based on the same table

    Hi group,
    Recently I ran into a problem with a UIX page that has two LOVs based on the same database table. In Emp and Job terminology, here's what I tried to do.
    Suppose we have use the Employees and Jobs tables from the HR scheme with one small modification. Add a column called PREFERRED_JOB_ID of type VARCHAR2(10) which is exactly the same as JOB_ID. Hypothetically speaking, this column will be used to allow Employees to select their preferred job in case they want to change their jobs.
    Next, create business components in JDeveloper based on the Employees and Jobs table. In order to be able to generate the LOVs for Job and PreferredJob create two ViewObjects, one called JobsLookupView and one called PreferredJobsLookupView. These both need to be based upon the same Jobs EntityObject. Also include the Jobs EntityObject twice in the EmployeesView ViewObject and give one the alias PreferredJobs. Include the JobTitle attributes of Jobs and PreferredJobs in EmployeesView so they can contain the JobTitles selected in our future LOVs.
    Next create a ViewController project if it's not already there and enable JHeadstart on it. Create an Application Structure File and create the lookups for the two LOVs. When I run the application I see this happening:
    When I click the flashlight icon next to the PreferredJob LOV and select a job, the PreferredJob field is selected in the UIX page but no job title appears. When I next first select the Job LOV and select a new job and then select the PreferredJob LOV again and select a different job, the job that was selected in the Job LOV is now also entered in the PreferredJob field. When I make sure the PreferredJob field isn't required (remove the required="yes" property on the messageLovInput entry for PreferredJobTitle and remove the PreferredJobTitle field from the addRequiredRowItems list in the UIX page) I can save the changes I made in the Employees.uix page. The same JobId is stored in the database for Job and PreferredJob.
    This behaviour is probably due to cacheing issues because both LOVs and the EmployeesView ViewObject use one EntityObject for four values in three ViewObjects.
    So I then modified my model a bit. I created a new EntityObject called PreferredJobs based on the JOBS table. I modified the EmployeesView ViewObject to use this EntityObject for the PreferredJobTitle attribute and modified the PreferredJobsLookupView to use this EntityObject.
    I needed to modify a few things as well in the Application Structure File (which were prompts and whether or not the attribute should be visible in a table) and after regenerating I made sure the PreferredJob attribute isn't required in the UIX page. When I then run the application again, I never see the JobTitle I select in any LOV allthough the PreferredJob field is selected when I select a Job in the PreferredJob LOV. The correct JobId now is stored in the database though.
    Has anyone ever encoutered this behaviour? Would anyone know how to get two LOVs based on the same table in one UIX page?
    Thanks in advance,
    Wouter van Reeven
    AMIS

    OK I figured it out. When I added the second Lookup ViewObject (PreferredJobs) no additional Association was created. Therefore, ADF BC wasn't able to figure out which field to update. When I added the Association between the PreferredJobs Lookup ViewObject and the Employees ViewObject everything started working ok.
    I then recreated my inital situation: one EntityObject for Jobs and one for Employees, now with two Associations between them. After modifying the Employees ViewObject and making sure the Jobs EntityObject was referred twice and via the corresponding Association, everything started working ok.
    Greets, Wouter
    AMIS

  • [ADF BC] Showing a list of values based on the contents of another list

    I have tried to make a simplified example to illustrate what I want to do. Here is a picture of my example schema:
    Example Schema Image
    There are three entity tables: Employee, Department and Location.
    There are also two intersection tabels: Employee_Location and Department_Location.
    My ADF BC model layer is based on this schema.
    What I am trying to do is have a creation process for an employee where you first fill in the employee details (forname and surname), then you assign the employee to a department, then - based on the locations assigned to the department - assign one or more locations to the employee.
    Imagine that the employee is a door-to-door salesman and that each department in is company has several areas of a town that they cover (locations). Each employee will cover a subset of the locations that the department covers.
    The first two steps are easy - the details page can be created using a form on the employee view and the department assignment can be done with a list of values drop down on the departments view.
    The third step is a little more complex. You can use a shuttle to assign one or more locations to the employee, but you shouldn't just show a list of all locations, since some of these will not be covered by the department and therefore not be available to the employee. What I want is only the locations associated with the employee's department to appear in the list.
    So my question is how do I model this using ADF Business Components?
    Also, if an employee is allowed to be assigned to more than one department (adding another intersection table between the employee and department tables), how would I model that?

    Hi,
    For your reference variable name should be simply any name i.e resorts_resort.No need to put @ in front when declaring variable and to refer presentation variable you should use the below syntax
    @{Variable_name}{Default_value} where default_value is some default value you want to give.
    Now coming to your problem you can fulfill your requirement by simply checking constrain checkbox.If you choose all values instaed of SQL results constrain checkbox will appear.Approach followed by you should also work but constrain is an easy option.
    Thanks
    Sandeep
    Edited by: Sandeep Saini on 10-Sep-2010 00:59
    Edited by: Sandeep Saini on 10-Sep-2010 00:59

  • Cannot See Components Added To JComponent

    Hi,
    It seems that components added to direct descendents of JComponent are not visible. Please see the following pseudocode:
    // In the following b is NOT visible:
    class MyComponent extends JComponent{}
    b = JButton("OK")
    p = MyComponent()
    p.add(b)
    f = JFrame()
    f.contentPane.add(p)
    f.show()
    // In the following b IS visible:
    b = JButton("OK")
    p = JPanel()
    p.add(b)
    f = JFrame()
    f.contentPane.add(p)
    f.show()
    How does one make JComponent-added components visible?
    Thanx
    --A                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

    Components and Containers are a bit different. Try calling paintChildren on your custom component like this:
    public void paintComponent(Graphics g){
       ...//do what you need to
       paintChildren(g);

  • I want to remove all the components from particular panel.

    hi all,
    i have 3 panels p,p1,p2.i added panels p1 and p2 to a window,then i added a panel p(this panel contaning JScrollPane) to a panel p1.i have a button on panel p2,if i press that button i want to remove all the components as well ass JScrollPane(remember JScrollPane in panel p).
    if possible give example.
    Thanks in advance
    bhaskar
    code is here
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    public class test1 extends Window implements ActionListener
    JPanel p,p1,p2;
    JScrollPane jp;
    Button b,b1,b2,b3,b4,b5,b6,b7,b8,b9,b10,b11,b12;
    test1()
    super(new Frame("testing"));
    p=new JPanel();
    p1=new JPanel();
    p2=new JPanel();
    adding();
    jp=new JScrollPane(p);
    jp.setPreferredSize(new Dimension(300,300));
    add(jp);
    setSize(new Dimension(200,200));
    setVisible(true);
    public void adding()
    b12=new Button("hai");
    b12.addActionListener(this);
    p2.add(b12);
    add(p1,BorderLayout.CENTER);
    add(p2,BorderLayout.WEST);
    p.setLayout(new GridLayout(11,1));
    p.setBackground(Color.white);
    b=new Button("one");
    b1=new Button("two");
    b2=new Button("three");
    b3=new Button("4");
    b4=new Button("5");
    b5=new Button("6");
    b6=new Button("7");
    b7=new Button("8");
    b8=new Button("9");
    b9=new Button("10");
    b10=new Button("11");
    b11=new Button("12");
    p.add(b);
    p.add(b1);
    p.add(b2);
    p.add(b3);
    p.add(b4);
    p.add(b5);
    p.add(b6);
    p.add(b7);
    p.add(b8);
    p.add(b9);
    p.add(b10);
    p.add(b11);
    p1.add(p);
    public void actionPerformed(ActionEvent e)
    if(e.getSource()==b12)
    System.out.println(e.getSource());
    System.out.println("111");
    p.removeAll();
    public static void main(String args[])
    test1 t=new test1();
    /*****************************************/

    p.removeAll();

Maybe you are looking for