Java2D/Swing bug? scrolling with painting JTextArea components hangs app

Please see
http://forum.java.sun.com/thread.jspa?threadID=653181

Please see
http://forum.java.sun.com/thread.jspa?threadID=653181

Similar Messages

  • Swing bug?: scrolling BLIT_SCROLL_MODE painting JTextArea components hangs

    java version "1.5.0_04"
    Hello,
    When drawing JComponent Text Areas and dynamically scrolling, Java gets confused, gets the shivers and freezes when the viewport cannot get its arms around the canvas. ;)
    Possible problem at JViewport.scrollRectToVisible().
    When painting non-text area components eg. graphics circles, it is ok.
    Have provided example code. This code is based on the ScrollDemo2 example provided in the Sun Java
    Tutorial
    thanks,
    Anil Philip
    juwo LLC
    Usage: run program and repeatedly click the left mouse button near right boundary to create a new JComponent node each time and to force scrolling area to increase in size to the right.
    When the first node crosses the left boundary, then the scroll pane gets confused, gets the shivers and hangs.
    The other scroll modes are a bit better - but very slow leaving the toolbar (in the oroginal application) unpainted sometimes.
    * to show possible bug when in the default BLIT_SCROLL_MODE and with JTextArea components.
    * author: Anil Philip. juwo LLC. http://juwo.com
    * Usage: run program and repeatedly click the left mouse button near right boundary to
    * create a new JComponent node each time and to force scrolling area to increase in size to the right.
    * When the first node crosses the left boundary, then the scroll pane gets confused, gets the shivers
    and hangs.
    * The other scroll modes are a bit better - but very slow leaving the toolbar (in the oroginal
    application)
    * unpainted sometimes.
    * This code is based on the ScrollDemo2 example provided in the Sun Java Tutorial (written by John
    Vella, a tutorial reader).
    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    /* ScrollDemo2WithBug.java is a 1.5 application that requires no other files. */
    public class ScrollDemo2WithBug extends JPanel {
    private Dimension area; //indicates area taken up by graphics
    private Vector circles; //coordinates used to draw graphics
    private Vector components;
    private JPanel drawingPane;
    public ScrollDemo2WithBug() {
    super(new BorderLayout());
    area = new Dimension(0, 0);
    circles = new Vector();
    components = new Vector();
    //Set up the instructions.
    JLabel instructionsLeft = new JLabel(
    "Click left mouse button to place a circle.");
    JLabel instructionsRight = new JLabel(
    "Click right mouse button to clear drawing area.");
    JPanel instructionPanel = new JPanel(new GridLayout(0, 1));
    instructionPanel.add(instructionsLeft);
    instructionPanel.add(instructionsRight);
    //Set up the drawing area.
    drawingPane = new DrawingPane();
    drawingPane.setBackground(Color.white);
    drawingPane.setPreferredSize(new Dimension(200, 200));
    //Put the drawing area in a scroll pane.
    JScrollPane scroller = new JScrollPane(drawingPane);
    // scroller.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
    if(scroller.getViewport().getScrollMode() == JViewport.BACKINGSTORE_SCROLL_MODE)
    System.out.println("BACKINGSTORE_SCROLL_MODE");
    if(scroller.getViewport().getScrollMode() == JViewport.BLIT_SCROLL_MODE)
    System.out.println("BLIT_SCROLL_MODE");
    if(scroller.getViewport().getScrollMode() == JViewport.SIMPLE_SCROLL_MODE)
    System.out.println("SIMPLE_SCROLL_MODE");
    //Lay out this demo.
    add(instructionPanel, BorderLayout.PAGE_START);
    add(scroller, BorderLayout.CENTER);
    /** The component inside the scroll pane. */
    public class DrawingPane extends JPanel implements MouseListener {
    private class VisualNode {
    int x = 0;
    int y = 0;
    int id = 0;
    public VisualNode(int id, int x, int y) {
    this.id = id;
    this.x = x;
    this.y = y;
    title.setLineWrap(true);
    title.setAlignmentY(Component.TOP_ALIGNMENT);
    titlePanel.add(new JButton("Hi!"));
    titlePanel.add(title);
    nodePanel.add(titlePanel);
    nodePanel.setBorder(BorderFactory
    .createEtchedBorder(EtchedBorder.RAISED));
    box.add(nodePanel);
    ScrollDemo2WithBug.this.drawingPane.add(box);
    Box box = Box.createVerticalBox();
    Box titlePanel = Box.createHorizontalBox();
    JTextArea title = new JTextArea(1, 10); // 1 rows x 10 cols
    Box nodePanel = Box.createVerticalBox();
    public void paintNode(Graphics g) {
    int ix = (int) x + ScrollDemo2WithBug.this.getInsets().left;
    int iy = (int) y + ScrollDemo2WithBug.this.getInsets().top;
    title.setText(id + " (" + ix + "," + iy + ") ");
    box.setBounds(ix, iy, box.getPreferredSize().width, box
    .getPreferredSize().height);
    int n = 0;
    DrawingPane() {
    this.setLayout(null);
    addMouseListener(this);
    protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    g.fill3DRect(10, 10, 25, 25, true);
    Point point;
    for (int i = 0; i < circles.size(); i++) {
    point = (Point) circles.elementAt(i);
    VisualNode node = (VisualNode) components.get(i);
    node.paintNode(g);
    //Handle mouse events.
    public void mouseReleased(MouseEvent e) {
    final int W = 100;
    final int H = 100;
    boolean changed = false;
    if (SwingUtilities.isRightMouseButton(e)) {
    //This will clear the graphic objects.
    circles.removeAllElements();
    area.width = 0;
    area.height = 0;
    changed = true;
    } else {
    int x = e.getX() - W / 2;
    int y = e.getY() - H / 2;
    if (x < 0)
    x = 0;
    if (y < 0)
    y = 0;
    Point point = new Point(x, y);
    VisualNode node = new VisualNode(circles.size(), point.x,
    point.y);
    // add(node);
    components.add(node);
    circles.addElement(point);
    drawingPane.scrollRectToVisible(new Rectangle(x, y, W, H));
    int this_width = (x + W + 2);
    if (this_width > area.width) {
    area.width = this_width;
    changed = true;
    int this_height = (y + H + 2);
    if (this_height > area.height) {
    area.height = this_height;
    changed = true;
    if (changed) {
    //Update client's preferred size because
    //the area taken up by the graphics has
    //gotten larger or smaller (if cleared).
    drawingPane.setPreferredSize(area);
    //Let the scroll pane know to update itself
    //and its scrollbars.
    drawingPane.revalidate();
    drawingPane.repaint();
    public void mouseClicked(MouseEvent e) {
    public void mouseEntered(MouseEvent e) {
    public void mouseExited(MouseEvent e) {
    public void mousePressed(MouseEvent e) {
    * Create the GUI and show it. For thread safety, this method should be
    * invoked from the event-dispatching thread.
    private static void createAndShowGUI() {
    //Make sure we have nice window decorations.
    JFrame.setDefaultLookAndFeelDecorated(true);
    //Create and set up the window.
    JFrame frame = new JFrame("ScrollDemo2");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //Create and set up the content pane.
    JComponent newContentPane = new ScrollDemo2WithBug();
    newContentPane.setOpaque(true); //content panes must be opaque
    frame.setContentPane(newContentPane);
    //Display the window.
    frame.setSize(800, 600);
    frame.pack();
    frame.setVisible(true);
    public static void main(String[] args) {
    //Schedule a job for the event-dispatching thread:
    //creating and showing this application's GUI.
    javax.swing.SwingUtilities.invokeLater(new Runnable() {
    public void run() {
    createAndShowGUI();
    }

    I changed the name so you can run this as-is without name clashing. It works okay now.
    import javax.swing.*;
    import javax.swing.border.EtchedBorder;
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    public class SD2 extends JPanel {
        public SD2() {
            super(new BorderLayout());
            //Set up the instructions.
            JLabel instructionsLeft = new JLabel(
                    "Click left mouse button to place a circle.");
            JLabel instructionsRight = new JLabel(
                    "Click right mouse button to clear drawing area.");
            JPanel instructionPanel = new JPanel(new GridLayout(0, 1));
            instructionPanel.add(instructionsLeft);
            instructionPanel.add(instructionsRight);
            //Set up the drawing area.
            DrawingPane drawingPane = new DrawingPane(this);
            drawingPane.setBackground(Color.white);
            drawingPane.setPreferredSize(new Dimension(200, 200));
            //Put the drawing area in a scroll pane.
            JScrollPane scroller = new JScrollPane(drawingPane);
            // scroller.getViewport().setScrollMode(JViewport.SIMPLE_SCROLL_MODE);
            if(scroller.getViewport().getScrollMode() == JViewport.BACKINGSTORE_SCROLL_MODE)
                System.out.println("BACKINGSTORE_SCROLL_MODE");
            if(scroller.getViewport().getScrollMode() == JViewport.BLIT_SCROLL_MODE)
                System.out.println("BLIT_SCROLL_MODE");
            if(scroller.getViewport().getScrollMode() == JViewport.SIMPLE_SCROLL_MODE)
                System.out.println("SIMPLE_SCROLL_MODE");
            //Lay out this demo.
            add(instructionPanel, BorderLayout.PAGE_START);
            add(scroller, BorderLayout.CENTER);
         * Create the GUI and show it. For thread safety, this method should be
         * invoked from the event-dispatching thread.
        private static void createAndShowGUI() {
            //Make sure we have nice window decorations.
            JFrame.setDefaultLookAndFeelDecorated(true);
            //Create and set up the window.
            JFrame frame = new JFrame("ScrollDemo2");
            frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            //Create and set up the content pane.
            JComponent newContentPane = new SD2();
            newContentPane.setOpaque(true);      //content panes must be opaque
            frame.setContentPane(newContentPane);
            //Display the window.
            frame.setSize(800, 600);
            frame.pack();
            frame.setVisible(true);
        public static void main(String[] args) {
            //Schedule a job for the event-dispatching thread:
            //creating and showing this application's GUI.
            javax.swing.SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    createAndShowGUI();
    /** The component inside the scroll pane. */
    class DrawingPane extends JPanel implements MouseListener {
        SD2 sd2;
        private Dimension area;     //indicates area taken up by graphics
        private Vector circles;     //coordinates used to draw graphics
        private Vector components;
        int n = 0;
        final int
            W = 100,
            H = 100;
        DrawingPane(SD2 sd2) {
            this.sd2 = sd2;
            area = new Dimension(0, 0);
            circles = new Vector();
            components = new Vector();
            this.setLayout(null);
            addMouseListener(this);
         * The 'paint' method is a Container method and it passes its
         * Graphics context, g, to each of its Component children which
         * use it to draw themselves into the parent. JComponent overrides
         * this Container 'paint' method and in it calls this method in
         * addition to others - see api. So the children of DrawingPane will
         * each paint themselves. Here you can do custom painting/rendering.
         * But this is not the place to ask components to paint themselves.
         * That would get swing very confused...
        protected void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.fill3DRect(10, 10, 25, 25, true);
            g.setColor(Color.red);
            Point point;
            for (int i = 0; i < circles.size(); i++) {
                point = (Point) circles.elementAt(i);
                g.fillOval(point.x-2, point.y-2, 4, 4);
        //Handle mouse events.
        public void mousePressed(MouseEvent e) {
            if (SwingUtilities.isRightMouseButton(e)) {
                //This will clear the graphic objects.
                circles.removeAllElements();
                components.removeAllElements();
                removeAll();                    // to clear the components
                area.width = 0;
                area.height = 0;
                setPreferredSize(area);
                revalidate();
                repaint();
            } else {
                int x = e.getX() - W / 2;
                int y = e.getY() - H / 2;
                if (x < 0)
                    x = 0;
                if (y < 0)
                    y = 0;
                Point point = new Point(x, y);
                VisualNode node = new VisualNode(this, circles.size(), point.x, point.y);
                // add(node);
                components.add(node);       // not needed
                circles.addElement(point);
                checkBoundries(x, y, node);
        private void checkBoundries(int x, int y, VisualNode node) {
            boolean changed = false;
            // since we used the setPreferredSize property to set the size
            // of each box we'll have to use it again to let the JScrollPane
            // know what size we need to show all our child components
            int this_width = (x + node.box.getPreferredSize().width + 2);
            if (this_width > area.width) {
                area.width = this_width;
                changed = true;
            int this_height = (y + node.box.getPreferredSize().height + 2);
            if (this_height > area.height) {
                area.height = this_height;
                changed = true;
            if (changed) {
                //Update client's preferred size because
                //the area taken up by the graphics has
                //gotten larger or smaller (if cleared).
                setPreferredSize(area);
                scrollRectToVisible(new Rectangle(x, y, W, H));
                //Let the scroll pane know to update itself
                //and its scrollbars.
                revalidate();
            repaint();
        public void mouseReleased(MouseEvent e) { }
        public void mouseClicked(MouseEvent e)  { }
        public void mouseEntered(MouseEvent e)  { }
        public void mouseExited(MouseEvent e)   { }
    * We are adding components to DrawingPanel so there is no need to get
    * into the paint methods of DrawingPane. Components are designed to draw
    * themseleves when their parent container passes them a Graphics context
    * and asks them to paint themselves into the parent.
    class VisualNode {
        DrawingPane drawPane;
        int x;
        int y;
        int id;
        Box box;
        public VisualNode(DrawingPane dp, int id, int x, int y) {
            drawPane = dp;
            this.id = id;
            this.x = x;
            this.y = y;
            box = Box.createVerticalBox();
            Box titlePanel = Box.createHorizontalBox();
            JTextArea title = new JTextArea(1, 10);     // 1 rows x 10 cols
            Box nodePanel = Box.createVerticalBox();
            title.setLineWrap(true);
            title.setAlignmentY(Component.TOP_ALIGNMENT);
            titlePanel.add(new JButton("Hi!"));
            titlePanel.add(title);
            nodePanel.add(titlePanel);
            nodePanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.RAISED));
            box.add(nodePanel);
            // here we are adding a component to drawPane so there is really
            // no need to keep this VisualNode in a collection
            drawPane.add(box);
            int ix = (int) x + drawPane.getInsets().left;
            int iy = (int) y + drawPane.getInsets().top;
            title.setText(id + " (" + ix + "," + iy + ") ");
            // since we are using the preferredSize property to setBounds here
            // we'll need access to it (via box) for the scrollPane in DrawPane
            // so we expose box as a member variable
            box.setBounds(ix, iy, box.getPreferredSize().width,
                                  box.getPreferredSize().height);
    }

  • Bug: scrolling with mouse scroll wheel while dragging tracks no longer works

    After upgrading to Spotify for Mac 1.0.2.6, I can no longer use my mouse's scroll wheel while dragging tracks to a different position in a playlist. This is an important feature when working with long playlists. Steps to reproduce:Create a playlist that extends past the bottom of the windowClick and begin dragging the first song on the playlist downwardUse your mouse's scroll wheel to scroll the playlist down. It will not scroll.

    Hey ,
    Thanks for letting us know.
    We don't have any update on this yet and we'll pass the information on to the right team.
    We'll keep you posted.
    Thanks! 

  • How to create scroller with paging concept for mobile apps?

    Hi,
    I need a scroller control with Paging concept. When the user is in Landscape view, I want to load set of images as a Photo gallary.
    Each time the user swipes, he can go to the next image or the previous image.
    Each image is fully fit in the whole page. Means the user can see only 1 image at a time. He needs to swipe left or right to see the previous or next image.
    When he double clicks the image, he will be taken to another page.
    Can you give your ideas of how to implement this feature?
    FYI: I have seen samples of List with Horizontal layout. But it does not suit with my requirement.

    did you even find a solution.. ?

  • SwingUtilities.paintComponent - problems with painting childs of components

    Maybe this question was mention already but i cant find any answer...
    Thats what could be found in API about method paintComponent in SwingUtilities:
    Paints a component c on an arbitrary graphics g in the specified rectangle, specifying the rectangle's upper left corner and size. The component is reparented to a private container (whose parent becomes p) which prevents c.validate() and c.repaint() calls from propagating up the tree. The intermediate container has no other effect.
    The component should either descend from JComponent or be another kind of lightweight component. A lightweight component is one whose "lightweight" property (returned by the Component isLightweight method) is true. If the Component is not lightweight, bad things map happen: crashes, exceptions, painting problems...
    So this method perfectly works for simple Java components like JButton / JCheckbox e.t.c.
    But there are problems with painting JScrollBar / JScrollPane (only background of this component appears).
    I tried to understand why this happens and i think the answer is that it has child components that does not draw at all using SwingUtilities.paintComponent()
    (JScrollBar got at least 2 childs - 2 buttons on its both sides for scroll)
    Only parent component appears on graphics - and thats why i see only gray background of scrollbar
    So is there any way to draw something like panel with a few components on it if i have some Graphics2D to paint on and component itself?
    Simple example with JScrollPane:
    JScrollPane pane = new JScrollPane(new JLabel("TEST"));
    pane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    pane.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    SwingUtilities.paintComponent(g2d, pane, new JPanel(), 0, 0, 200, 200);Edited by: mgarin on Aug 11, 2008 7:48 AM

    Well the thing you advised could work... but this wont be effective, because i call repaint of the area, where Components painted, very often..
    So it will lag like hell when i make 10-20 repaints in a second... (for e.g. when i drag anything i need mass repainting of the area)
    Isnt there any more optimal way to do painting of the sub-components?
    As i understand when any component (even complicated with childs) paints in swing - its paint method calls its child components paint() to show them... can this thing be reproduced to paint such components as JScrollPane?

  • Flyweight Pattern use with multiple GUI components

    Hi,
    I am creating a simple application and I would like your advice on wether I should use the flyweight pattern or not.
    My application is essentially a GUI front to a repository of small images. The GUI (in its simplest form) is a single window that will display all the images with their names in a clickable thumbnail format. The user will be able to select an thumbnail icon, drag it and move it around pretty much like the icons on your computer desktop.
    The easiest way to do that is probably to load each image and its name into a JLabel, add it in a JFrame and write just few lines of code (say by extending the JLabel class) to handle mouse pressed/dragged events in order to move the label around. The rest will be taken care of by the swing functinality (e.g. painting etc).
    However, I am considering using the flyweight pattern for efficiency but I am not sure if it is appropriate. So far I have seen simplistic examples of its use (apart from JTree) where the pattern is used to paint dozens of lines on the screen or the borders of components. But what happens if instead of lines or borders the objects in question are interactive GUI components such as my thumbnails? how does the flyweight pattern work in this case?
    For example if I create just a single JLabel and use it to paint all my icons that's great! but what happens with mouse events? what happens when I want to drag a thumbnail over another one and how the partial repainting of the thumbnail below should be handled?
    Am I missing something here, or in order to implement the flyiweight pattern in this case I will have to write endless lines of code to replicate the functionality that swing arleady provides in each JComponent? (e.g. targetting of mouse events, repainting etc)
    Cheers,
    Kyri

    I don't think Flyweight applies, because you really don't want to share any UI component that generates events unless the response is the same for all of them.
    If you read Flyweight, I think it was intended for things like caching the first 128 Integers, etc. - think finite, countable, immutable things. I don't think UI elements apply.
    %

  • How to print a dialog box with all its components ?

    Hi !
    I've written an application.It has a dialog box [JDialog] containing following components:
    1) 2 JLabels.
    1) A JTextField.
    3) A JTable with some values.
    4) A JProgressBar.
    5) A JButton.
    6) An animated gif image.
    I want to print the dialog box with all its components exactly as the are [ Except the button & animated gif ].
    Would anybody please help me?
    My Operating System: Windows XP

    The article over at http://java.sun.com/developer/technicalArticles/Printing/Java2DPrinting/ has some helpful information on printing Swing components.
    It suggests creating a subclass of the JComponent that you want to print, and have it implement Printable interface.
    So, something like (note, uncompiled / untested code alert) :
    import java.awt.Frame;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.HeadlessException;
    import java.awt.print.PageFormat;
    import java.awt.print.Printable;
    import javax.swing.JDialog;
    public class PrintableDialog extends JDialog implements Printable {
          * Or whichever constructor you need...
         public PrintableDialog(Frame owner, String title, boolean modal) throws HeadlessException {
              super(owner, title, modal);
          * Implementation of the Printable interface.
           public int print(Graphics g, PageFormat pf, int pageIndex) {
              if (pageIndex != 0) return NO_SUCH_PAGE;
              Graphics2D g2 = (Graphics2D) g;
              g2.translate(pf.getImageableX(), pf.getImageableY());
              getContentPane().paint(g2);
              return PAGE_EXISTS;
    }Cheers,
    John

  • Re: not happy with layout of components

    I have written the front end of a banking application.
    The problem is I am not happy with how the components are positioned.
    Any suggestion?
    I am using gridlayout(7,2)
    6 rows are made up of mainly labels and textfield.
    One row is a panel, which has other components.
    The problem is there is a large gap between the labels and the next component.
    Here is the code:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class BankUI extends JFrame {
    JLabel jlabel1, jlabel2, jlabel3, jlabel4, jlabel5, jlabel6,
    jlabel7, jlabel8, jlabel9, jlabel10;
    JCheckBox jcheckbox1, jcheckbox2;
    JTextField jtextfield1, jtextfield2, jtextfield3, jtextfield4;
    private JComboBox jcombobox1, jcombobox2, jcombobox3;
    private String days[] = { "1","2","3","4","5","6","7","8","9",
    "10","11","12","13","14","15","16","17",
    "18","19","20","21","22","23","24",
    "25","26","27","28","29","30","31"};
    private String month[] = { "January", "February", "March", "April",
    "May", "June", "July", "August", "September",
    "October", "November", "December"};
    private String year[] = { "1970", "1971","1972","1973","1974","1975","1976",
    "1977","1978","1979",
    "1980", "1981","1982","1983","1984","1985","1986",
    "1987","1988","1989",
    "1990", "1991","1992","1993","1994","1995","1996",
    "1997","1998","1999",
    "2000", "2001", "2002", "2003"};
    private JPanel jpanel;
    private Container c;
    private GridLayout gridlayout;
    public BankUI()
    super( "Scruple Bank");
    gridlayout = new GridLayout(7,2);
    c = getContentPane();
    c.setLayout(gridlayout);
    jlabel1 = new JLabel("Surname:");
    jtextfield1 = new JTextField(20);
    c.add(jlabel1);
    c.add(jtextfield1);
    jlabel2 = new JLabel("First name:");
    jtextfield2 = new JTextField(20);
    c.add(jlabel2);
    c.add(jtextfield2);
    jlabel3 = new JLabel("Address:");
    jtextfield3 = new JTextField(20);
    c.add(jlabel3);
    c.add(jtextfield3);
    jlabel4 = new JLabel();
    jtextfield4 = new JTextField(20);
    c.add(jlabel4);
    c.add(jtextfield4);
    jlabel5 = new JLabel("Date of birth:");
    c.add(jlabel5);
    jpanel = new JPanel();
    c.add(jpanel);
    jlabel6 = new JLabel("Day");
    jcombobox1 = new JComboBox(days);
    jcombobox1.setMaximumRowCount(3);
    jpanel.add(jlabel6);
    jpanel.add(jcombobox1);
    jlabel7 = new JLabel("Month");
    jcombobox2 = new JComboBox(month);
    jcombobox2.setMaximumRowCount(3);
    jpanel.add(jlabel7);
    jpanel.add(jcombobox2);
    jlabel8 = new JLabel("Month");
    jcombobox3 = new JComboBox(year);
    jcombobox3.setMaximumRowCount(3);
    jpanel.add(jlabel8);
    jpanel.add(jcombobox3);
    jlabel9 = new JLabel();
    jcheckbox1 = new JCheckBox("Payment Protection");
    c.add(jlabel9);
    c.add(jcheckbox1);
    jlabel10 = new JLabel();
    jcheckbox2 = new JCheckBox("Card Protection");
    c.add(jlabel10);
    c.add(jcheckbox2);
    setSize(750,300);
    show();
    public static void main(String args[])
    BankUI app = new BankUI();
    app.addWindowListener(
    new WindowAdapter() {
    public void windowClosing(WindowEvent e)
    System.exit(0);

    I have an open source layout called AttachLayout that a member of this forum gave to me awhile back. It greatly assisted me and you can check it out here:
    http://www.compaq.com/java/download/attachlayout/
    It's easy and intuitive.
    Let me know if you need more assistance or have difficulty getting the classes.

  • Help required building ADF-Swing/ADF-Faces using ADF Business Components

    My question is in regards to how you can go about building a light swing application to an ADF model?
    In particular if I were to say that we were developing a 3-tier project whereby we had a database tier, a series of EJB-ADF façade session beans to the database (middle-tier), and a swing client communicating with the session beans (view-controller tier), how would you go about developing these screens?
    In particular can we develop these screens using ADF-Faces and also ADF-Swing?
    The EJB session façade beans of course are ADF app modules with customised methods. The methods would return back customised DTO objects. These DTO objects are wrappers to row objects ADF would create. This would be mainly due to making these facade beans web service enabled (Oracle state that these methods cannot return oracle.jbo objects if they are to be web service enabled).
    This would be typically deployed to an app server, like Oracle App Server 10G.
    Could you please have a look at this, as I am doing a lot of research into this.
    eg. Taking example from oracle magazine sept/oct 2006
    with slight enhancements
    package oramag.frameworks.example.common;
    import oracle.jbo.ApplicationModule;
    import oramag.frameworks.customdto.EmployeeDTO;
    public interface HRService extends ApplicationModule {
    void deleteCurrentEmpAndCommit();
    EmployeeDTO findEmployee(int employeeId); // new method
    import oramag.frameworks.customdto.EmployeeDTO;
    public class HRServiceImpl extends ApplicationModuleImpl {
    public void deleteCurrentEmpAndCommit() {
    Row empRow = getEmpView().getCurrentRow();
    if (empRow != null) {
    empRow.remove();
    getDBTransaction().commit();
    public EmployeeDTO findEmployee(int employeeId)() {
    EmployeeDTO employeeDTO = null;
    EmployeesImpl employees = getEmployees();
    employees.setNamedWhereClauseParam("EmployeeId", employeeId);
    employees.executeQuery();
    if(employees.hasNext()) {
    EmployeesRowImpl employee = (EmployeesRowImpl)employees.next();
    employeeDTO = new EmployeeDTO(employee);
    return employeeDTO;
    public EmployeesImpl getEmployees() {
    return (EmployeesImpl)findViewObject("Employees");
    Now given the above code snippet, how could you turn this into an ADF-Swing/ADF Faces application so that if a user using the swing application enters an employee id, then the application will execute the query on the app server, the app server in turn returns the results to the client, and the client finally display the results. Typical MVC example.
    Cheers
    Rodney

    The tutorial is for ADF BC used with JavaServer Faces.
    While the tutorial doesn't cover it, we also support drag and drop development for Swing and visual WYSIWYG layout for Swing panels and windows, too. For a very simple example, watch screencast #4 on my blog here:
    http://radio.weblogs.com/0118231/stories/2005/06/24/jdeveloperAdfScreencasts.html
    One thing I have noticed is that when using ADF business components, when the app module returns a custom DTO object like the above example, it returns the data in a element structure according to the data control palette.
    You don't generally ever need to create your own custom DTO's when working with ADF for use by client UI's. The only situation where can be necessary -- until we simplify this in the JDeveloper/ADF 11g release -- is when you desire to expose custom methods that can return sets/arrays of typed row structures through a web service. However, web services are not involved/required in building 3-tier Swing applications.
    When dropping onto a page it does so like a string and doesnt give option to display the data in a read only form etc. Is there anything we need to do, to get the functionality.
    It's more of what you don't need to do :-)
    Just leverage the active data model that the ADF application module provides. You can read more about it in section 4.5 "Understanding the Active Data Model" of the ADF Developer's Guide for Forms/4GL Developers on the ADF Learning Center at http://www.oracle.com/technology/products/adf/learnadf.html). Your UI's bind to view object instances in the data model, and your UI's are automatically kept up to date without needing to write methods that return data. I short article I wrote that preceeded my writing the ADF Developer Guide content on this topis is here:
    http://radio.weblogs.com/0118231/stories/2006/01/26/theAdfBusinessComponentsActiveDataModel.html
    I know that when dropping a view object you get this functionality. Also was wondering if we were to pass an object of thios type back to the model it might not give us the rich functionality like input forms, like what Oracle provides if we were to drop a enitity view object.
    Just use the active data model and everything becomes totally easy, with no changes required to switch between local or three-tier deployment configurations.
    Trying to do everything with hand-coded DTO beans is really going the hard way.
    Could you help us regarding this?

  • "detected a page fragment with multiple root components" warning

    I am getting a warning on the standalone WLS when I run my page that contains a taskflow as region. I am using a page fragment in my taskflow.
    <Warning> <oracle.adfinternal.view.faces.renderkit.rich.RegionRenderer> <ADF_FACES-60099> <The region component with id: ptMain:r1 has detected a page fragment with multiple root components. Fragments with more than one root component may not display correctly in a region and may have a negative impact on performance. It is recommended that you restructure the page fragment to have a single root component.>
    The warning states the obvious, I have everything within a panelheader in my page fragment. Also, I do not get the warning on the integrated WLS. Any ideas as to why this warning is still popping up in the log? I am using JDev 11.1.1.3.
    Thanks,
    Jessica

    Thank you for responding. I do not have any popups. I do, however, have another region nested within this fragment ( have this warning on another fragment that doesn't have a nested region though). Here is the code for my fragment.
    <?xml version='1.0' encoding='UTF-8'?>
    <jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1"
    xmlns:af="http://xmlns.oracle.com/adf/faces/rich"
    xmlns:f="http://java.sun.com/jsf/core">
    <af:panelHeader text="Pawn"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.ph1}"
    id="ph1" type="default">
    <af:panelFormLayout id="pfl2">
    <af:panelSplitter binding="#{backingBeanScope.backing_Fragments_PawnSearch.ps1}"
    id="ps1" orientation="vertical" splitterPosition="62"
    inlineStyle="width:775px; height:660px;">
    <f:facet name="first">
    <af:panelBox text="Search #{bindings.agency.inputValue} Data to Update"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.pb1}"
    id="pb1">
    <f:facet name="toolbar"/>
    <af:panelGroupLayout id="pgl3" layout="horizontal">
    <af:inputText value="#{bindings.control_number.inputValue}"
    label="Control Number" required="true"
    columns="#{bindings.control_number.hints.displayWidth}"
    maximumLength="#{bindings.control_number.hints.precision}"
    shortDesc="#{bindings.control_number.hints.tooltip}"
    id="it1">
    <f:validator binding="#{bindings.control_number.validator}"/>
    </af:inputText>
    <af:inputDate value="#{bindings.trans_date.inputValue}"
    label="Date" required="true"
    shortDesc="#{bindings.trans_date.hints.tooltip}"
    id="id1">
    <f:validator binding="#{bindings.trans_date.validator}"/>
    <af:convertDateTime pattern="#{bindings.trans_date.format}"/>
    </af:inputDate>
    <af:inputText value="#{bindings.agency.inputValue}" simple="true"
    required="#{bindings.agency.hints.mandatory}"
    columns="#{bindings.agency.hints.displayWidth}"
    maximumLength="#{bindings.agency.hints.precision}"
    shortDesc="#{bindings.agency.hints.tooltip}"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.it2}"
    id="it2" visible="false">
    <f:validator binding="#{bindings.agency.validator}"/>
    </af:inputText>
    <af:commandButton actionListener="#{bindings.ExecuteWithParams.execute}"
    text="Search"
    disabled="#{!bindings.ExecuteWithParams.enabled}"
    id="cb5"
    returnListener="#{backingBeanScope.backing_Fragments_PawnSearch.refreshPage}"
    action="#{backingBeanScope.backing_Fragments_PawnSearch.RenderMe}">
    <af:setActionListener from="#{bindings.PawnItemView1Iterator.currentRowKeyString}"
    to="#{requestScope.pawnkey}"/>
    </af:commandButton>
    <af:spacer width="10" height="10"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.s1}"
    id="s1"/>
    <af:goButton text="Clear Values and Create New" id="gb1"
    destination="index.jspx"
    rendered="#{backingBeanScope.backing_Fragments_PawnSearch.saveButtonRendered}"/>
    </af:panelGroupLayout>
    </af:panelBox>
    </f:facet>
    <f:facet name="second">
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl4}"
    id="pgl4" layout="scroll" partialTriggers=""
    visible="true">
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl6}"
    id="pgl6" inlineStyle="width:775px;"
    visible="#{backingBeanScope.backing_Fragments_PawnSearch.renderTF}">
    <af:region value="#{bindings.PawnEntryFormTF1.regionModel}"
    id="r1" inlineStyle="width:750px;"/>
    </af:panelGroupLayout>
    <af:panelGroupLayout binding="#{backingBeanScope.backing_Fragments_PawnSearch.pgl5}"
    id="pgl5" layout="horizontal"
    visible="#{backingBeanScope.backing_Fragments_PawnSearch.renderMessage}">
    <af:outputFormatted value="No #{bindings.agency.inputValue} Pawn data matching the Control Number and Transaction Date from above."
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.of1}"
    id="of1"
    inlineStyle="font-weight:bolder; font-size:small;"/>
    <af:spacer width="10" height="10"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.s2}"
    id="s2"/>
    <af:goButton text="Clear Search and Start Again"
    binding="#{backingBeanScope.backing_Fragments_PawnSearch.gb2}"
    id="gb2" destination="index.jspx"/>
    </af:panelGroupLayout>
    </af:panelGroupLayout>
    </f:facet>
    </af:panelSplitter>
    </af:panelFormLayout>
    </af:panelHeader>
    <!--oracle-jdev-comment:auto-binding-backing-bean-name:backing_Fragments_PawnSearch-->
    </jsp:root>

  • JDev 10.1.3.3 - issues with imported Business Components

    Hi,
    I have got some issues with importing Business Components in JDev 10.1.3.3.
    I cannot discover/use the imported components.
    What I did is the folowing:
    1. In a existing project I extended the default base-classes to create our own layer
    2. created a project called ModelShared
    2a. configured the project to use the base-classes I created in step 1
    2b. created an entitybased-viewobject (RefCodesByDomain)
    2c. created bc deployment-descriptors
    3. created a project called RelatieModel in the same workspace as ModelShared
    3a. added dependencies to the deployment-descriptors as well as the project created in step 2
    3b. configured the project to use the base-classes I created in step 1
    3c. imported business components
    Although I did not recieve any errors during the import of business components, I am unable to add the vo (RefCodesByDomain) to a service.
    I do see the package which contains the vo but is has no entries.
    Importing the business components to a new BC Project in a seperate workspace did succeed (I could reuse the vo).
    I tested a little further and the folowing occurred:
    4. I created a new vo in the ModelShared Project
    5. I deployed the ModelShared
    6. Restarted JDeveloper
    7. Got the folowing error message in the console window when expanding a service in my datacontrol pallette:
    INFO: oracle.adf.share.config.ADFConfigFactory No META-INF/adf-config.xml found
    1-sep-2008 13:23:27 oracle.adf.dt.controls.DataControlsTreeWillExpandListener treeWillExpand
    FINER: THROW
    java.lang.NullPointerException
            at oracle.adf.dt.objects.JUDTViewReferenceAccessorDefinition.init(JUDTViewReferenceAccessorDefinition.java:108)
            at oracle.adf.dt.objects.JUDTViewReferenceAccessorDefinition.<init>(JUDTViewReferenceAccessorDefinition.java:98)
            at oracle.adfdt.internal.meta.bc4j.BC4JDataControlDefinition.createViewObjectDefinition(BC4JDataControlDefinition.java:228)
            at oracle.adfdt.internal.meta.bc4j.BC4JDataControlDefinition.addViewObjects(BC4JDataControlDefinition.java:208)
            at oracle.adfdt.internal.meta.bc4j.BC4JDataControlDefinition.loadStructure(BC4JDataControlDefinition.java:110)
            at oracle.adfdt.internal.meta.bc4j.BC4JDataControlDefinition.getStructure(BC4JDataControlDefinition.java:407)
            at oracle.adf.dt.controls.treemodel.jsr227.JSR227DataControlTreeNode.loadChildNodes(JSR227DataControlTreeNode.java:129)
    8. In my other "fresh" bc project I was able to use the newly created vo.
    9. When I added a VO to my shared project, all projects that are refering to the shared project loose their vo's in the data-controlpannel
    Do you have any suggestions?
    Regards,
    Romano

    Hi,
    since this appears to be a WebCenter related issue, I suggest to try the Webcenter forum WebCenter Portal or to log a bug
    Frank

  • How do I display a JDialog with a JTextArea in it?

    Hello.
    How do I display a JDialog with a JTextArea in it?

    http://java.sun.com/docs/books/tutorial/uiswing/mini/index.html
    import javax.swing.*;
    import java.awt.*;
    public class Test extends JDialog{
         public Test(){
              JPanel contentPane = new JPanel(new BorderLayout());
              JTextArea ta = new JTextArea();
              ta.setText("JDialog with a JTextArea in it");
              setContentPane(contentPane);
              contentPane.add(ta);
              setSize(300,300);
              setVisible(true);
         public static void main(String[] args){
              new Test();
    }     

  • Swing bug? cannot set width of JToggleButton

    Hello,
    Just wondered if this was a Swing bug. See also
    bug 6349010.
    The width of the JToggleButton cannot be set.
    However the height can be set.
    The important line is line 135 - and also 140.
    Try changing the width of the button - it does not change.
    thanks,
    Anil
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.util.EventObject;
    import javax.swing.BorderFactory;
    import javax.swing.Box;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JScrollPane;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    import javax.swing.JToggleButton;
    import javax.swing.JTree;
    import javax.swing.UnsupportedLookAndFeelException;
    import javax.swing.tree.DefaultMutableTreeNode;
    import javax.swing.tree.DefaultTreeCellEditor;
    import javax.swing.tree.DefaultTreeCellRenderer;
    import javax.swing.tree.DefaultTreeModel;
    import javax.swing.tree.TreeSelectionModel;
    public class TreeUIFailed extends JPanel {
           AnilTreeCellRenderer3 atcr;
           AnilTreeCellEditor4 atce;
           DefaultTreeModel treeModel;
           JTree tree;
           DefaultMutableTreeNode markedNode = null;
         public TreeUIFailed() {
                super(new BorderLayout());
                   treeModel = new DefaultTreeModel(null);
                   tree = new JTree(treeModel);          
                  tree.setEditable(true);
                   tree.getSelectionModel().setSelectionMode(
                             TreeSelectionModel.SINGLE_TREE_SELECTION);
                   tree.setShowsRootHandles(true);
                  tree.setCellRenderer(atcr = new AnilTreeCellRenderer3());
                  tree.setCellEditor(atce = new AnilTreeCellEditor4(tree, atcr));
                  tree.setRowHeight(0);//TEMP - needed only if setting Win L&F
                   JScrollPane scrollPane = new JScrollPane(tree);
                   add(scrollPane,BorderLayout.CENTER);
         public void setRootNode(DefaultMutableTreeNode node) {
              treeModel.setRoot(node);
              treeModel.reload();
           public static void main(String[] args) throws ClassNotFoundException, InstantiationException, IllegalAccessException, UnsupportedLookAndFeelException{
    //            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
                TreeUIFailed tb = new TreeUIFailed();
                tb.setPreferredSize(new Dimension(800,600));
                  JFrame frame = new JFrame("Tree Windows UI Failed");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setContentPane(tb);
                  frame.setSize(800, 600);
                  frame.pack();
                  frame.setVisible(true);
                  tb.populate();
         private void populate() {
              TextAreaNode3 r = new TextAreaNode3(this);
               setRootNode(r);
                   r.gNode.notes.addTab("0", null/* icon */, new JTextArea(2,25),
                   "no menu!");
                   r.gNode.notes.addTab("1", null/* icon */, new JTextArea(2,25),
                   "no menu!");
                   TextAreaNode3 a = new TextAreaNode3(this);
                   a.gNode.notes.addTab("1", null/* icon */, new JTextArea(2,25),
                   "no menu!");
               treeModel.insertNodeInto(a, r, r.getChildCount());          
    class AnilTreeCellRenderer3 extends DefaultTreeCellRenderer{
         TreeUIFailed panel;
    DefaultMutableTreeNode currentNode;
      public AnilTreeCellRenderer3() {
         super();
    public Component getTreeCellRendererComponent
       (JTree tree, Object value, boolean selected, boolean expanded,
       boolean leaf, int row, boolean hasFocus){
         TextAreaNode3 currentNode = (TextAreaNode3)value;
         NodeGUI4 gNode = (NodeGUI4) currentNode.gNode;
        return gNode.vBox;
    class AnilTreeCellEditor4 extends DefaultTreeCellEditor{
      DefaultTreeCellRenderer rend;
      public AnilTreeCellEditor4(JTree tree, DefaultTreeCellRenderer r){
        super(tree, r);
        rend = r;
      public Component getTreeCellEditorComponent(JTree tree, Object value,
       boolean isSelected, boolean expanded, boolean leaf, int row){
        return rend.getTreeCellRendererComponent(tree, value, isSelected, expanded,
         leaf, row, true);
      public boolean isCellEditable(EventObject event){
        return true;
    * this is done to keep gui separate from model - as in MVC.
    * not necessary.
    * @author juwo
    class NodeGUI4 {
         JPanel notesPanel = new JPanel(new BorderLayout(), true);
         JTabbedPane notes = new JTabbedPane(JTabbedPane.RIGHT);
         final TreeUIFailed view;
         Box vBox = Box.createVerticalBox();
         Box hBox = Box.createHorizontalBox();
         final JTextArea textArea = new JTextArea( 1, 5 );
         JToggleButton toggleButton = new JToggleButton();
         NodeGUI4( TreeUIFailed view_ ) {
              this.view = view_;
              toggleButton.setAlignmentX(Component.CENTER_ALIGNMENT);
    // BEGIN PROBLEM          
              toggleButton.setPreferredSize(new Dimension(200,toggleButton.getPreferredSize().height));
    // END PROBLEM
              vBox.add(toggleButton);
              vBox.add(hBox);
              hBox.add( textArea );
              textArea.setBorder( BorderFactory.createMatteBorder( 0, 0, 1, 0, Color.GREEN ) );
              notesPanel.add(notes);
              hBox.add( notesPanel);
              hBox.setBorder( BorderFactory.createMatteBorder( 5, 5, 5, 5, Color.CYAN ) );
    // THE FOLLOWING DOES NOT WORK EITHER!!!          
              //          halo.setPreferredSize(new Dimension(vBox.getPreferredSize().width,halo.getPreferredSize().height));
    class TextAreaNode3 extends DefaultMutableTreeNode {  
         NodeGUI4 gNode;
         TextAreaNode3(TreeUIFailed view_t) {     
              gNode = new NodeGUI4(view_t);          
    }

    ok, sorry!
    I understood why it does not work.
    Box Layout respects the maximum size of the component.
    By default, a JToggleButton is set to 34.
    Changing the JToggleButton max width to 75, allows the preferred size to be set.
    Thank you camickr!
    Note: in contrast, Flow Layout respects the preferred size and ignores the max size!
    Message was edited by:
    anilp1

  • Problems with disappearing JTextArea when activating JMenu

    Im having trouble with using JTextArea in conjunction with JMenu and JInternalFrame. I have a program that uses JInternalFrames for navigation, when the navigation been used I set the JInternalFrame to setVisible(false) and display a JMenuBar with several components and a JTextArea. The JTextArea gets displayed as it should and so is the JMenuBar but when a JMenuItem has been activated the JTextArea becomes invisible or partly invisible. Anyone have any suggestions?
    //Function that removes the JInternalFrame and adds the JMenuBar and JTextArea to the program
    public void ordBehandlare()
                   ramnav.setVisible(false); //ramnav == JInternalFrame
                   Container cont = getContentPane();
                   cont.add(ordbehandlarArea); //ordbehandlarArea == JTextArea
                   setJMenuBar(ordBehandBar); //ordBehandBar == JMenuBar
    Grateful for any answers...

    From the 5 lines of code you posted I have no idea whats wrong, but I'm sure you can create a 20 line program that we can compile and execute that demonstrates your problem. Chances are while your creating this simple program you will find your error.

  • Scrolling with mouse on pages create black and white lines,

    When scrolling with mouse, periodically the whole screen turns into black and white lines. Sometimes whole page, sometimes just pictures/side ads. If you continue to scroll it does go away but then you need to scroll back to where the lines started, its hard to explain, i have taken 1 photo of the problem but will take more photos as i can, i really enjoy how Firefox runs on my computer, it has always been the best browser for my needs. I did recently buy a new desktop, but it did it then also, so i removed it and tried running explorer and Google and i just don't like them, so i am hoping we can get this fixed.

    Try to disable hardware acceleration in Firefox.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    *https://support.mozilla.org/kb/Troubleshooting+extensions+and+themes
    *https://hacks.mozilla.org/2010/09/hardware-acceleration/
    If there is a problem with scrolling on web pages then try to disable smooth scrolling.
    *Tools > Options > Advanced > General: Browsing: "Use smooth scrolling"

Maybe you are looking for

  • G-RAID with thunderbolt to Firewire adapter

    Hi, I just bought a brand new Macbook Pro with Retina display.  I also purchased a Thunderbolt to Firewire800 adapter with it to plug in the G-RAID mini disks I already had.  WHen I try to plug the G-RAID mini in the TBtoFW adapter it make a regular

  • White Macbook 13" will not boot - Stuck in Safe Boot mode

    In a nutshell -- macbook will not boot.  Originally it was stuck on the gray screen with spinning wheel.  Here is the course of action taken thus far (in order) 1.  Reset SMC -- removed battery, pushed power button for 5-1 seconds.  Rrestsarted.  Not

  • FTP Adapter : java.lang.NullPointerException

    Hi, I am getting a java.lang.NullPointerException when I try to use the FTP Adapter. The message monitor for the Adapter shows this: 2006-02-27 16:48:57 Success File adapter receiver channel OMAF_PO_FTPS_Rcvr: start processing: party " ", service "OM

  • Transferring music from nano ipod to itunes

    I have a ton of songs on my ipod that I would like to put into itunes. Is there a special program I need to do that? If so what is it? Thank you!

  • How to delete Pending WIP Move Transactions with running status

    hello, can any one guide me, how to delete Pending WIP Move Transactions with running status thanks in advance sadiq