Clearing GUI components displayed in a JFrame window

Hi Programmers and Developers,
Good day to y'all!
My application displays a number of GUI components on the screen. I intend to design a JButton that can clear the window of all these GUI components when it is clicked. Is there a method that can erase already displayed GUI's or is their a technique i can implement to achieve this??
Many Thanks and Merry Xmas!

You clear components the in much the same way that you added them
See Container.remove(Component)
You will of course want to call validate(); repaint() after removing a component.
Make a small dummy app to test this out.
You might also want to look at tjacobs.ui.util.ComponentMapper (which you can find in TUS). It may make finding the components you want to remove easier

Similar Messages

  • GUI components not clearing from JDialog closing

    Greetings,
    I have developed an application which works on several different computers with several different JVMs, but which does not operate as anticipated on my (new) tablet PC. It leaves GUI components on the main JFrame from various Jdialog boxes (after closing them) that I throw at the user when the program starts.
    I also have a username/password prompt at the beginning which is another JFrame that doesn't appear correctly. The input areas do not appear with a white background and the Username and Password JLabels have echoed themselves into that area.
    I'm guessing this is Windows XP, Tablet Edition issue. I'd like to know if anyone else has experienced anything similar?
    FYI, this programs works quite well on Windows 98, Windows XP Home and Professtional, Windows 2000, and Windows ME.
    Any help would be most appreciated.
    Regards

    Hi all,
    I am trying to develop a Java application on the Tablet PC. I am new to this platform and could not find much information about Java related Tablet PC development .So I am posting this question here
    Details
    I have developed a Swing Application in Java (J2SDK 1.4.2) for a Client, which currently runs on Windows XP on the Standard Laptop. The application uses the following
    1) Menus
    2) Panels
    3) Dialogs
    It consists of an entry form, which is saved as an XML file on the user's computer. Also it uses an Access Database.
    The other thing that the application uses is a Signature Capture Device to capture a user's signature
    I would like to move this application to the Tablet PC.
    I have the following questions
    1) What SDK do I use for the Tablet PC? Also what version of Java web start and Run time?
    2) What kind of changes do I need to make in my application?
    3) Can I make use of the "Ink" feature, which is provided with a Tablet PC in Java?
    4) Where can I find user samples if any for Java Tablet PC development?
    BTW I am using Toshiba Prot�g� 3500 for my project.
    Thanks,
    Raja

  • Rescale GUI-Components on resizeing frame?

    Hello,
    how do I have to implement rescaling GUI-components when a frame (JFrame) is resized by a user on runtime?
    Should I have to use the observer-observable-pattern?
    thanx

    If you've got a layout manager then its automatic otherwise add a WindowListener to capture the resize event then resize them yourself.
    Rob.

  • Need help:JPanel not being displayed in the JFrame

    Hello,
    I have a class called ConstructRoom.java which extends JFrame and another class called DimensionsPanel.java which extends JPanel. In the ConstructRoom class I use the following theContainer.add(new DimensionsPanel());, so I can display my JPanel. Well I get the JFrame but no JPanel. When the this call is made the DimensionsPanel.java code is cycled through, Where has my JPanel gone to?
    If I change the DimensionPanel.java extend JFrame and add the the JFrame code. Then I get the JFrame and the JPanel.
    Whats going on here?
    Thanks

    I made some of the changes with no luck. Here is some of the code:
    ---------from ConstructRoom.java--------
    //Imports
    public class ConstructRoom extends JFrame
    //----Member objects and varibles
    private static String theTitle; //Varible for title of frame
    private JFrame theFrame; //Object for the JFrame
    // ----------------------------------------------------------- ConstructRoom
    public ConstructRoom(String theTitle)
    super(theTitle); //JFrame super class
    theFrame = new JFrame("My frame");
    Container theContainer = theFrame.getContentPane(); //Frame container
    theContainer.setLayout(new FlowLayout());
    theContainer.add(new DimensionsPanel());
    theFrame.pack();
    theFrame.setBounds(10,10,400, 400);
    theFrame.addWindowListener(new WindowHandler());
    theFrame.setVisible(true);
    }//end ConstructRoom(String theTitle)
    // -------------------------------------------------------------------- main
    public static void main(String args[])
    ConstructRoom theRoom = new ConstructRoom(theTitle);
    }//end main(String args[])
    //----WindowHander
    }//end class ConstructRoom extends JFrame
    --------from DimensionsPanel.java
    //Imports
    public class DimensionsPanel extends JPanel
    //----Member objects and varibles
    private JPanel dimensionsPanel; //The main panel to hold all info
    private Box panelBox; //Box for all boxes which is added to the JPanel
    private Box furnListBox; //Box for all related items of the furnList
    private Box dimensionsBox; //Box for all dimensions (x, y, z)
    private Box xFieldBox; //Box for all related items of the xField
    private Box yFieldBox; //Box for related items of the yField
    private Box zFieldBox; //Box for related items of the zField
    private Box buttonsBox; //Box for all buttons
    private Box clearBox; //Box for related clear button items
    private Box buildBox; //Box for related build button items
    private JLabel furnListLabel; //Label for the furnList comboBox
    private JLabel xFieldLabel; //Label for the xField
    private JLabel yFieldLabel; //Label for yField
    private JLabel zFieldLabel; //Label for zField
    private JTextField xField; //Text field to enter the x dimension
    private JTextField yField; //Text field to enter the y dimension
    private JTextField zField; //Text field to enter the z dimension
    private JComboBox furnList; //List of selectable furniture objects
    private JButton clearButton; //Clear button
    private JButton buildButton; //Build button
    // --------------------------------------------------------- DimensionsPanel
    public DimensionsPanel()
    //----Setting up dimensions panel
    dimensionsPanel = new JPanel();
    dimensionsPanel.setLayout(new BorderLayout());
    dimensionsPanel.setPreferredSize(new Dimension(150,150));
    dimensionsPanel.setBorder(new TitledBorder(new EtchedBorder(),
    "Select Furniture and Enter Dimensions"));
    //----Initializing GUI components
    furnListLabel = new JLabel("Select from list ");
    furnList = new JComboBox();
    xFieldLabel = new JLabel("Enter Width ");
    xField = new JTextField();
    yFieldLabel = new JLabel("Enter Height ");
    yField = new JTextField();
    zFieldLabel = new JLabel("Enter Depth ");
    zField = new JTextField();
    buildButton = new JButton("Build Object");
    clearButton = new JButton("Clear Object");
    //-----Setting up the combo box and adding items
    furnList.addActionListener(new ComboProcessor());
    furnList.addItem(" "); //Default item
    furnList.addItem("Color Cube");
    furnList.setMaximumRowCount(6); //Max number of items before scrolling
    furnList.setSelectedItem(" "); //Set initial to default item
    //--Add the furnList to its box for placement in the JPanel
    furnListBox = Box.createHorizontalBox();
    furnListBox.add(Box.createHorizontalStrut(5));
    furnListBox.add(furnListLabel); //Adding the combo box label
    furnListBox.add(furnList); //Adding the combo box
    furnListBox.add(Box.createHorizontalStrut(5)); //Spacing
    //-------------------------------- Start Dimensions Components
    //----Setting up the xField
    xField.setEnabled(false); //Disabled at start
    xField.setFocusTraversalKeysEnabled(false); //Disabling the Tab Key
    //----Adding the event listeners
    xField.addActionListener(new XTextProcessor()); //Enter Key
    xField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the xField to its box for placement in the dimensionsBox
    xFieldBox = Box.createHorizontalBox();
    xFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    xFieldBox.add(Box.createGlue()); //Take up extra space
    xFieldBox.add(xFieldLabel); //Adding the text field label
    xFieldBox.add(xField); //Adding the text field
    xFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Setting up the yfield
    yField.setEnabled(false); //Disabled at start
    yField.setFocusTraversalKeysEnabled(false); //Disabling TAB KEY
    //----Adding the event listeners
    yField.addActionListener(new YTextProcessor()); //Enter Key
    yField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the yField to its box for placement in the dimensionsBox
    yFieldBox = Box.createHorizontalBox();
    yFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    yFieldBox.add(Box.createGlue()); //Take up extra space
    yFieldBox.add(yFieldLabel); //Adding the text field label
    yFieldBox.add(yField); //Adding the text field
    yFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Setting up the zfield
    zField.setEnabled(false); //Disabled at start
    zField.setFocusTraversalKeysEnabled(false); //Disabling TAB KEY
    //----Adding the event listeners
    zField.addActionListener(new ZTextProcessor()); //Enter Key
    zField.addMouseListener(new ClickProcessor()); //Mouse Click
    //--Add the zField to its box for placement in the dimensionsBox
    zFieldBox = Box.createHorizontalBox();
    zFieldBox.add(Box.createHorizontalStrut(10)); //Spacing
    zFieldBox.add(Box.createGlue()); //Take up extra space
    zFieldBox.add(zFieldLabel); //Adding the text field label
    zFieldBox.add(zField); //Adding the text field
    zFieldBox.add(Box.createHorizontalStrut(100)); //Spacing
    //----Adding all dimension components to the dimensionsBox
    dimensionsBox = Box.createVerticalBox();
    dimensionsBox.add(xFieldBox); //Adding the xFieldBox
    dimensionsBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsBox.add(yFieldBox); //Adding the yFieldBox
    dimensionsBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsBox.add(zFieldBox); //Adding the zFieldBox
    //-------------------------------- End Dimension Components
    //----Setting up the clearButton
    clearButton.setEnabled(false); //Disabled at start
    //----Adding the event listener
    clearButton.addActionListener(new ClearProcessor());
    //--Add the clear button to its box for placement
    clearBox = Box.createHorizontalBox();
    clearBox.add(Box.createHorizontalStrut(5)); //Spacing
    clearBox.add(clearButton); //Adding the clearButton
    //----Setting up the buildButton
    buildButton.setEnabled(false); //Disabled at start
    //--Add the action listener here
    buildBox = Box.createHorizontalBox();
    buildBox.add(buildButton); //Adding the buildButton
    buildBox.add(Box.createHorizontalStrut(5)); //Spacing
    //----Adding both buttons the buttonsBox
    buttonsBox = Box.createHorizontalBox();
    buttonsBox.add(clearBox); //Adding the clearBox
    buttonsBox.add(Box.createHorizontalStrut(10)); //Spacing
    buttonsBox.add(buildBox); //Adding the buildBox
    //----Create the JPanel (dimensionsPanel)
    //--Creating the main box to be added to the JPanel
    panelBox = Box.createVerticalBox();
    panelBox.add(furnListBox); //Adding the furnListBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    panelBox.add(dimensionsBox); //Adding the dimensionBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    panelBox.add(buttonsBox); //Adding the buttonsBox components
    panelBox.add(Box.createVerticalStrut(10)); //Spacing
    dimensionsPanel.add(panelBox); //Adding all components to the JPanel
    System.out.println("end dimensionpanel");
    }//end DimensionsPanel()
    //------ActionListeners
    }//end class DimensionsPanel extends JPanel

  • 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.
    %

  • Customer gui components needed?

    I require to build a program with which allows the user to add representations of objects onto the main GUI by adding a seperate square for each object. each square should be capable of being moved, resized, deleted as well as have text displayed in it, and another object associated with it (but I'm currently just dealing with the GUI side of things). Each square will also need to be connected to others by means of an arrow from one square to another. Any suggestions as to where to start as there does not seem to be any appropriate widgets provided by java for this and I am having trouble finding stuff on the net about it. Will creating my own custom GUI components be the best option? If so any tips on how to do this?
    Regards

    Hello Ravi,
    Create a Variable for 0CALMONTH, and use this code,
    ' Declare this in the top
    data : v_startmon(6) type n,
    v_endmon(6) type n,
    ' Include this in the case statement
    when 'VarName'.
    ' Step 2 will execute after the user Input
    if i_step = 2.
    v_year = sy-datum(4).
    v_mon = sy-datum+4(2) - 1.
    ' If the month is Jan
    IF v_mon = '00'.
    CONCATENATE v_year '01' INTO v_startmon.
    CONCATENATE v_year '01' INTO v_endmon.
    ELSE.
    CONCATENATE v_year '01' INTO v_startmon.
    CONCATENATE v_year v_mon INTO v_endmon.
    EndIF.
    clear l_s_range.
    l_s_range-low = v_startmon.
    l_s_range-high = v_endmon.
    l_s_range-sign = 'I'.
    l_s_range-opt = 'BT'.
    append l_s_range to e_t_range.
    Endif.
    Please see this for
    [User Exits in SAP BW|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/23f2f094-0501-0010-b29b-c5605dbdaa45]
    [User Exit Examples|https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/6378ef94-0501-0010-19a5-972687ddc9ef]
    Also see this
    [Dependencies for Variables of Type Customer Exit |http://help.sap.com/saphelp_nw04/helpdata/en/1d/ca10d858c2e949ba4a152c44f8128a/content.htm]
    Thanks
    Chandran
    Edited by: Chandran Ganesan on Mar 17, 2008 1:57 PM

  • GUI not displaying

    I cannot get the GUI for this class to display at all. The could will compile and run but only a small GUI appears with none of my buttons or controls on it. The complete GUI code is below. Any ideas?
    Thanks
    Mick
    package shareddilog;
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.*;
    import javax.swing.event.*;
    import javax.swing.border.*;
    /*This class is used for sharing files and folders and is a GUI class. It is mainly
    used for sharing files and directories for users to use. Through this class the
    listener can add files and directories for sharing */
    public class Shareddilog extends JDialog implements ActionListener
    public void actionPerformed(ActionEvent e)
    public void shared_files()
    //Create an object of the JDialog class
    sharedilog = new JDialog();
    //Set the layout as null and draw the GUI components as needed
    sharedilog.getContentPane().setLayout(null);
    sharedilog.setTitle("Share Dialog");
    //adding the window listener
    addWindowListener(new WindowAdapter()
    public void windowClosing(WindowEvent e)
    dispose();
    //Initialising the GUI Component
    share_file=new JButton("Share File");
    //Positioning the the GUI Component
    share_file.setBounds(10,7,100,20);
    //Adding an ActionListener
    share_file.addActionListener(this);
    //Adding the button
    sharedilog.getContentPane().add(share_file);
    share_folder=new JButton("Share Folder");
    share_folder.setBounds(110,7,150,20);
    share_file.addActionListener(this);
    sharedilog.getContentPane().add(share_folder);
    l_type=new JLabel();
    l_type.setText("Type a filename here or click browse to select");
    l_type.setBounds(15,35,380,20);
    sharedilog.getContentPane().add(l_type);
    t_type=new JTextField(150);
    t_type.setBounds(15,60,380,20);
    sharedilog.getContentPane().add(t_type);
    browse=new JButton("Browse");
    browse.setBounds(315,85,80,20);
    browse.add(this);
    sharedilog.getContentPane().add(browse);
    c_entry=new JCheckBox("Add this entry only");
    c_entry.setBounds(275,110,150,20);
    sharedilog.getContentPane().add(c_entry);
    /*When this button is pressed the information regarding the file/folder share
    will be added to the share.ini file*/
    shared_it=new JButton("Share it");
    shared_it.setBounds(250,165,80,20);
    shared_it.addActionListener(this);
    sharedilog.getContentPane().add(shared_it);
    /*This button is for closing the Dialog */
    close=new JButton("Close");
    close.setBounds(340,165,80,20);
    close.addActionListener(this);
    sharedilog.getContentPane().add(close);
    //This RadioButton gives read only permission to the file
    read_only=new JRadioButton("Read Only",true);
    read_only.setBounds(10,140,80,20);
    sharedilog.getContentPane().add(read_only);
    //This RadioButton gives gives read/write permissions to the file
    read_write=new JRadioButton("Read/Write",false);
    read_write.setBounds(10,165,80,20);
    sharedilog.getContentPane().add(read_write);
    group=new ButtonGroup();
    //Adding RadioButtons to the group so only one can be selected
    group.add(read_only);
    group.add(read_write);
    JDialog sharedilog;
    JButton share_file;
    JButton share_folder;
    JLabel l_type;
    JTextField t_type;
    JButton browse;
    JCheckBox c_entry;
    JButton shared_it;
    JButton close;
    JRadioButton read_only;
    JRadioButton read_write;
    ButtonGroup group;
    Vector v_file_list;
    DataInputStream data_in;
    BufferedReader data_buffer_in;
    static boolean b_cho_f=false;
    static boolean b_cho_d=false;
    JFileChooser fileselection;
    String r_reights;
    long lengthoffile;
    static File file_list;
    static boolean value_all_ready_present = false;
    StringTokenizer st;
    String s_line;
    static boolean first_time_entry = false;
    DataOutputStream data_out;
    public static void main(String[] args)
    Shareddilog s=new Shareddilog();
    s.show();

    Well it pretty easy. I've taken out the code that is unused so you can see what is going on.
    import javax.swing.* ;
    public class Shareddilog extends JDialog
    public static void main(String[] args)
    Shareddilog s=new Shareddilog();
    s.show();
    }This is the only code that is executed in your program. It created a JDialog and then shows it. What you want to do, I imagine, is to put all the GUI stuff in your constructor and make sure you call pack() on it before you are done.

  • Problem displaying CheckboxGroup on JFrame

    I was recently assigned the task of creating exams. I am trying to create a CheckboxGroup in a class that was passed the Graphics2D tool. This code compiles with no errors when I call it's method:
    setLayout(new GridLayout(1, 5));
              CheckboxGroup cbg = new CheckboxGroup();
              add(new Checkbox("Never", cbg, false));
              add(new Checkbox("Almost Never", cbg, false));
              add(new Checkbox("Sometimes", cbg, false));
              add(new Checkbox("Almost All The Time", cbg, false));
              add(new Checkbox("All The Time", cbg, false));
    but nothing displays on my JFrame, I tried to draw it with this line(g2 is my Graphics2D tool):
    g2.draw(cbg);
    but I get an error when compiling that says draw doesn't work. Am I totally off-track with this or is there a simple Graphics2D method that I use to draw this CheckboxGroup?

    hiwa: Thanks for the tip, I won't mix those libraries anymore
    pete: Here is all of my code so far sorry it's sloppy, I'm just getting back into coding after one semester of Intro to Computer Science using Java almost a year ago::/*this class has main function**************************************************/
    import javax.swing.JFrame;
    import javax.swing.JOptionPane;
    public class PDS_Questionnaire
         public static void main(String[] args)
              //declare JFrame window dimensions
              int WIDTH = 500;
              int HEIGHT = 400;
              //create JFrame
              JFrame frame = new JFrame();
              frame.setSize(HEIGHT, WIDTH);
              frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              //create object of painter class to install onto frame
              ScoreCard survey = new ScoreCard();
              //add object to frame and set visible
              frame.add(survey);
              frame.setVisible(true);
    /*********************end of class***************************************/
    /****************************new class**********************************/
    //this class is the JFrame painter, it initiates the Graphics2D class then passes the
    //Graphics object to PDS_Scorer so that the PDS_Scorer class can draw on the patientsCard
    import javax.swing.JComponent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    public class ScoreCard extends JComponent
         public ScoreCard()
         public void paintComponent(Graphics g)
              //recover Graphics2D
              Graphics2D g2 = (Graphics2D) g;
                    //create another class and pass the Graphics2D tool
              PDS_Scorer patientsCard = new PDS_Scorer(g2);
                    //call method to draw the check boxes
              patientsCard.drawCheckBoxes();
    /*********************end of class***************************************/
    /****************************new class**********************************/
    import javax.swing.JComponent;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.GridLayout;
    import java.awt.Checkbox;
    import java.awt.CheckboxGroup;
    public class PDS_Scorer extends JComponent
         public PDS_Scorer(Graphics2D gTwo)
              g2 = gTwo;
         public void partA_Scorer()
         public void partB_Scorer()
         public void partC_Scorer()
         public void partD_Scorer()
         public void partE_Scorer()
         public void partF_Scorer()
         public void drawCheckBoxes()
    //           draw3DRect(int x, int y, int width, int height, boolean raised)
    //      Draws a 3-D highlighted outline of the specified rectangle.
              g2.draw3DRect(10, 10, 10, 10, true);   //this works
              setLayout(new GridLayout(1, 5));
              CheckboxGroup cbg = new CheckboxGroup();
              add(new Checkbox("Never", cbg, false));
              add(new Checkbox("Almost Never", cbg, false));
              add(new Checkbox("Sometimes", cbg, false));
              add(new Checkbox("Almost All The Time", cbg, false));
              add(new Checkbox("All The Time", cbg, false));
            //g2.drawString("One Lazy Fox", 22.5, 55.5);
         private Graphics2D g2;
    }

  • Save GUI components in a XML format

    I am looking for a technoology that can help to create a my own file format using java. That mean currently im working with implementing a mind mapping tool (like mindjet) which will help to do basic mind mapping actions like add, edit, delete topics.
    But I have faced for a ig problem when im saving a created map. because it should save as a new file format and should be able to re-open for editing.
    What I planned is to retrive the GUI component's(elements of the map) properties from the map and write those values to the XML file(using XML DOM or SAX). Then read those saved values and create the GUI components under retrieved data.
    what I want to know is that. Is my approach is correct? or is there any better solution for this matter?
    please clarify me and I would really appreciate your help?
    Regards
    Lakshitha Ranasinghe

    You presumably have some state, in memory, that you want to persist. From your post, though I must confess that the terms you use are not really clear in terms of what type of data you actually want to say, my guess is that you have some graph of objects in memory that you have parsed that you want to serialize and persist and then later deserialize and restore for reuse in a subsequent execution of your program.
    If yes, then your goal is really simple: how do I save the state of my application and then restore it?
    Go to the filesystem: store as a properties file (key-value pairs), Java's default serialization, XML or a totally custom format
    Go do the database: map your object to a proper database table and column (via JDBC or an O/R mapper ala Hibernate), or store what you would have stored in the filesystem in a databaseXML is a valid option. So is a simple properties file. It depends on your requirements. If you are reading from and writing to a Java application, and frequent versioning is not an issue, then Java's default serialization could be a possibility. Going to the database would be the 'enterprise' solution, but requires testing and the successful functioning and communication between two technologies and machines. It depends on your requirements.
    - Saish

  • Positioning of GUI components

    a question for the java veterans out there,
    i am a student of programming and i wish to learn how to place/position GUI components in java by hard coding it. Is there any trick/technique that this could be done easily? I don't want to rely on netbeans's GUI maker to make my programs's GUI for the rest of my life.
    any help is appreciated.
    (please don't make it quite complicated. ^_^)

    Hi,
    The link to the tutorial you requested is [Laying out Components within a Container|http://java.sun.com/docs/books/tutorial/uiswing/layout/index.html], more specific [Doing Without a Layout Manager (Absolute Positioning)|http://java.sun.com/docs/books/tutorial/uiswing/layout/none.html]. But I would suggest you start to learn using the default layout managers first before you venture out into the wild lands named 'absolute positioning'. The layout mangers supplied by Sun (and made by a big bunch of seasoned Sun Java Programmers) help you when something happens in your screen, like resizing the window. If you use absolute positioning you have to handle such cases yourself.
    Abel

  • GUI Components & Graphical drawings

    Hi,
    I�m new to Swing (haven�t done much GUI since Motif!) and I�m a little confused about the relationship between GUI components and �drawn� graphics.
    In my application I have two JPanels � an upper and a lower � that display two views of the same data,
    In both of these JPanels I do my graph drawing using g.drawXXX() or g.fillXXX().
    I label the displays using g.drawString()
    However, I want to add some checkboxes to one of the JPanel displays that will trigger actions in the other JPanel. I�m not sure how to get the checkboxes to show up in the right place. It feels like the GUI components work in Layout mode whereas the graphics are in x,y coordinate space.
    I see that JComponent has setLoaction / setBounds methods � but I�ve not had any joy with these so far.
    I can see that I could create my own JComponent subclass that has the GUI and the graphics area and this could use a Layout to line things up.
    Basically � can I draw GUI components at an x,y coordinate on a JPanel?
    If this sounds like bad practice I�d welcome any sources of reference.
    Many thanks.

    Hi,
    My question probably sounds more complicated than it is owing to my inexperience with Swing. I'm sure what I'm after is done thousands of time in other apps.
    Bascially I have two set of graphs -
    One is pure graphical (plotting stock prices etc.).
    The other contains horizontal "bar" format data that lines up below the stock price graph
    (Again see latest posting here : http://www.chriswardsweblog.blogspot.com/)
    What I'm after is to have some controls at the right hand end of each bars. Presently I would imagine these to be a JCheckBox and maybe a JLabel to replace the g.drawString() rendered label in the screenshot.
    The reason I want this is that the upper graph area shows a plotted view of the bar data. I want to be able to check/uncheck the box to see the plotted quote lines turn on/off.
    I am pretty sure that I need to divide that lower JPanel into a "Graphical" panel for the bars and a "Component" panel for the controls. That feels like the correct thing to do - I just wanted someone to confirm I wasn't getting the wrong end of ths stick.
    If this is the case - I think I need to sort out what Layout I should use that will allow me to get the JCheckbox & JLabel to line up with the bars. I have been look at the Box layout which would seem to allow me to do that.
    I have another open question in this forum about how to toggle the visibilty of the upper panel quote lines - maybe that's where I need a Glass Panel?
    Does this clarify things?
    Thanks for all help.

  • TS1717 My iTunes kepps freezing and changing my display seetings on my Windows 7

    Why is iTunes download changing my display settings for my Windows 7 and not working correctly?

    This is ppfaceannagrace, the question asker. I had to clear up one thing or the many things that I should make more clear. Sorry I didn't proof read, or run spell check.
    I wrote When I wrote my, "My book is written on Microsoft words not Microsoft word". I meant I worte part of the book on Microsoft Works NOT Microsoft Word! Thanks for taking time to read *hopefully at least the part where I ask the question* If not the other longer, less, or really not at all important info.

  • How to create a array of GUI components?

    Hello, everyone!
    I need help or advice how to create an GUI components array. As I remenber in VB this possible just by calling two or more buttons (for example) with the same name. The API will authomatically create an array: Buton[0], Button[1], Button[2] and so on...
    In Java it possible as well:
    JButton button[];
    button = new JButton[10];
    for ( int i = 1; i < 10; i++ ){
    button[i] = new JButton();
    ....and so on....
    But my problem is that I use Forte for Java v. 3.0 and when I using Frame Editor it does not allow me to call two components with the same name and at the same time does not allow to change the initialization code painted in blue color...
    Does anyone knows how to avoid this, or how to create GUI components array in Forte for Java API using Frame Editor or Component Inspector???
    All that I need is few buttons accessible by index ( button[1], button[2] etc.) I will apreciate any help or advise.
    Thank you in advance,
    Michael

    I tried using Forte after having used Windows notepad and found that I
    like notepad much better. If you seem to be having problems with Forte,
    you might just try writing this portion of code in a regular text editor
    and compiling it with a command line compiler. Hope this helps some.

  • Just upgraded to snow leopard, downloader apple support drivers for canon mp620.  Why won't a printer list display in add printer window?

    Just upgraded to snow leopard, downloader apple support drivers for canon mp620.  Why won't a printer list display in add printer window?

    Assuming the MP620 is connected to your wireless network, then there are two components to this device - the printer and the scanner. The printer uses Canon proprietary software while the scanner is supported by Apple's Bonjour service. So in many cases, you will at least see the scanner, shown as Bonjour Scanner in the Kind column, while the printer can take longer to appear and is shown as canonijnetwork in the Kind column. If you cannot see either then you have a network issue. Try turning off the MP620 for a minute and then turning back on. Then see if the scanner / printer component appears in the Add Printer window. If you still don't see either, then confirm the MP and the Mac are using the same network. If you know the MP's IP address you can use Network Utility to Ping the address. You can also enable Bonjour Bookmarks in Safari preferences and when selected, the MP620 should appear.

  • How to resize a custom tree node like you would a JFrame window?

    Hello,
    I am trying to resize a custom tree node like you would a JFrame window.
    As with a JFrame, when your mouse crosses the Border, the cursor should change and you are able to drag the edge to resize the node.
    However, I am faced with a problem. Border cannot detect this and I dont want to use a mouse motion listener (with a large number of nodes, I fear it will be inefficient, calculating every node's position constantly).
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Component;
    import java.awt.Dimension;
    import java.awt.Insets;
    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.JTextArea;
    import javax.swing.JTree;
    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 ResizeNode extends JPanel {
           AnilTreeCellRenderer2 atcr;
           AnilTreeCellEditor2 atce;
           DefaultTreeModel treeModel;
           JTree tree;
           DefaultMutableTreeNode markedNode = null;
         public ResizeNode() {
                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 AnilTreeCellRenderer2());
                  tree.setCellEditor(atce = new AnilTreeCellEditor2(tree, atcr));
                   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){
                ResizeNode tb = new ResizeNode();
                tb.setPreferredSize(new Dimension(400,200));
                  JFrame frame = new JFrame("ResizeNode");
                  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                  frame.setContentPane(tb);
                  frame.setSize(400, 200);
                  frame.pack();
                  frame.setVisible(true);
                  tb.populate();
         private void populate() {
              TextAreaNode2 r = new TextAreaNode2(this);
               setRootNode(r);
               TextAreaNode2 a = new TextAreaNode2(this);
               treeModel.insertNodeInto(a, r, r.getChildCount());          
    class AnilTreeCellRenderer2 extends DefaultTreeCellRenderer{
    TreeBasic panel;
    DefaultMutableTreeNode currentNode;
      public AnilTreeCellRenderer2() {
         super();
    public Component getTreeCellRendererComponent
       (JTree tree, Object value, boolean selected, boolean expanded,
       boolean leaf, int row, boolean hasFocus){
         TextAreaNode2 currentNode = (TextAreaNode2)value;
         NodeGUI2 gNode = (NodeGUI2) currentNode.gNode;
        return gNode.box;
    class AnilTreeCellEditor2 extends DefaultTreeCellEditor{
      DefaultTreeCellRenderer rend;
      public AnilTreeCellEditor2(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;
    class NodeGUI2 {
         final ResizeNode view;
         Box box = Box.createVerticalBox();
         final JTextArea aa = new JTextArea( 1, 5 );
         final JTextArea aaa = new JTextArea( 1, 8 );
         NodeGUI2( ResizeNode view_ ) {
              this.view = view_;
              box.add( aa );
              aa.setBorder( BorderFactory.createMatteBorder( 0, 0, 1, 0, Color.GREEN ) );
              box.add( aaa );
              box.setBorder( BorderFactory.createMatteBorder( 5, 5, 5, 5, Color.CYAN ) );
         private Dimension getEditorPreferredSize() {
              Insets insets = box.getInsets();
              Dimension boxSize = box.getPreferredSize();
              Dimension aaSize = aa.getPreferredSize();
              Dimension aaaSize = aaa.getPreferredSize();
              int height = aaSize.height + aaaSize.height + insets.top + insets.bottom;
              int width = Math.max( aaSize.width, aaaSize.width );
              if ( width < boxSize.width )
                   width += insets.right + insets.left + 3;     // 3 for cursor
              return new Dimension( width, height );               
    class TextAreaNode2 extends DefaultMutableTreeNode {  
         NodeGUI2 gNode;
         TextAreaNode2(ResizeNode view_) {     
              gNode = new NodeGUI2(view_);
    }

    the node on the tree is only painted on using the
    renderer to do the painting work. A mouse listener
    has to be added to the tree, and when moved over an
    area, you have to determine if you are over the
    border and which direction to update the cursor and
    to know which way to resize when dragged. One of the
    BasicRootPaneUI has some code that can help determine
    that.Thanks for replying. What is your opinion on this alternative idea that I just had?
    I am wondering if it might be easier to have a toggle button in the node that you click when you want to resize the node. Then a mouse-down and dragging the mouse will resize the node. Mouse-up will reset the toggle button, and so will mouse down in an invalid area.
    Anil

Maybe you are looking for