Help in jtfeditor in swing

can someone show me a code which shows the working of rtfeditor in jeditorpane.i want to have the multiple text format effect that u have in yahoo chat room.u can have multiple coloured text and multi script letters in the same text field at the same time.

here u go why dont u rite like a normal intelligent person cause maybe things would work out better 4 u if u did?
http://java.sun.com/docs/books/tutorial/uiswing/components/generaltext.html

Similar Messages

  • 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?

  • Help with problems in Swing

    Hi, I am trying to develop a simple applet where a user can click on the screen to add jbuttons at the location of the mouse click. I have written an overly complex set of code that tries to achieve this goal, and in the end I have come close. My applet allows the user to input a certain number, and then click that many times on screen to create more jbuttons. The problem is that whenever the user clicks on screen a jbutton is created, but it only appears once the mouse has moved over it. I find this pretty weird, but basically when the user clicks, a jbutton is created within the program, but it is only "drawn" to the screen when the mouse moves directly over it.
    www.geocities.com/nickv360
    Can anyone explain to me why this is happening?
    http://www.geocities.com/nickv360/Source/AirlineModel.java
    http://www.geocities.com/nickv360/Source/City.java
    http://www.geocities.com/nickv360/Source/DrawingCanvas.java
    These are the source files if that helps at all. Addtinonally, the reset button doesn't work. The way the applet is supposed to be set up is to have an array of cities (JButtons) stored in DrawingCanvas. The drawing Canvas then accesses that cities[] array and adds each city[i] to the map. If there are no cities in the cities[] array, then no cities will be added. So, in order to successfully reset the map, here is what I do:
    cities = new City[numCities];
    removeAll();
    index = 0;
    repaint();
    I change the cities[] array to a new array of cities. I use the removeAll() method to take away all the JButtons that are currently on the map, I reset the index counter, and I repaint. Unfortunately this doesn't work.
    Does anyone know why Swing won't paint my buttons until the mouse moves over them, and why the reset method I've written doesn't work? Thanks in advance to anyone who can help.

    Just wanted to let people know that I found the answer:
    As for the other problem, I think it has to do with you having overridden paint. Normally, when you call repaint on a container, it will automatically call repaint on all the components that it contains. I'm fairly certain that if you don't manually call super.paint(g); in your paint method, it won't do it for you.
    Calling super.paint(g) makes the all of the bugs in the code disappear.
    Thanks.

  • Help about TreeTable in Swing

    Hi,
    I am using JIDE for GUI development in my project. Almost all the JIDE components are extends Swing Component. For example (JButton in the swing is JideButton in JIDE). As all you know that TreeTable is something which will show the information with Tree with column header. For example (File system). Please see the example by clicking link ([http://java.sun.com/products/jfc/tsc/articles/treetable1/] ).
    I have requirement in project where I need to show the 2 table (Parent and Child) information in database in TableTree view with specific format where parent table column will display as header then row of first parent table and then column of child table with all corresponding child row data (S). For example please see the example screen shot (Which is developed in one of the DOT NET tool) by clicking link [http://usera.ImageCave.com/ssidiq/TesRunScreenShoot.bmp.jpg|http://usera.imagecave.com/ssidiq/TesRunScreenShoot.bmp.jpg]
    Can some one help me to develop by giving suggestion? Which component in Swing will be suitable for my requirement?
    Thanks
    Sidiq

    Hi,
    I am using JIDE for GUI development in my project. Almost all the JIDE components are extends Swing Component. For example (JButton in the swing is JideButton in JIDE). As all you know that TreeTable is something which will show the information with Tree with column header. For example (File system). Please see the example by clicking link ([http://java.sun.com/products/jfc/tsc/articles/treetable1/] ).
    I have requirement in project where I need to show the 2 table (Parent and Child) information in database in TableTree view with specific format where parent table column will display as header then row of first parent table and then column of child table with all corresponding child row data (S). For example please see the example screen shot (Which is developed in one of the DOT NET tool) by clicking link [http://usera.ImageCave.com/ssidiq/TesRunScreenShoot.bmp.jpg|http://usera.imagecave.com/ssidiq/TesRunScreenShoot.bmp.jpg]
    Can some one help me to develop by giving suggestion? Which component in Swing will be suitable for my requirement?
    Thanks
    Sidiq

  • Plz help me in creating swing interface

    Hi,
    Iam new to swing.I have one Interface on swing.Now I want to add Jfilechooser object in my interface for selecting file from hard drive.So that I can upload this file through my servlet uploading programme.I want to set remote url also for saving the file.But I confused how I can do that.Plz guide me.
    I try to create one interface but iam sure it is not the correct way.Can u plz try with my codes. Below r my codes:
    import javax.swing.AbstractAction;
    import javax.swing.Action;
    import javax.swing.JToolBar;
    import javax.swing.JButton;
    import javax.swing.ImageIcon;
    import javax.swing.JMenuItem;
    import javax.swing.JCheckBoxMenuItem;
    import javax.swing.JMenu;
    import javax.swing.JFrame;
    import javax.swing.JMenuBar;
    import javax.swing.JTextArea;
    import javax.swing.JPanel;
    import javax.swing.JLabel;
    import javax.swing.JScrollPane;
    import javax.swing.JProgressBar;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.event.*;
    import java.util.*;
    import javax.swing.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    import javax.swing.accessibility;
    public class ActionDemo1 extends JFrame implements ActionListener
         JTextArea textArea,textArea1,textArea2,textArea3,textArea4,textArea5,textArea6,textArea7,
         textArea8,textArea9,textArea10,textArea11,textArea12,textArea13,textArea14,textArea15;
         private JProgressBar progressBar;          
         private JButton Button,Button1,Button2;     
         URL url;
         BufferedReader in;
         String str;
    public ActionDemo1()
                        setTitle("Upload Interface");                               
                        addWindowListener(new WindowAdapter()
                             public void windowClosing(WindowEvent e)
                                  System.exit(0);
         Container contentPane = getContentPane();          
         JMenuItem menuItem = null;
    JToolBar toolBar = new JToolBar();
         JToolBar toolBar1 = new JToolBar();     
         JToolBar toolBar2 = new JToolBar();
         JToolBar toolBar3 = new JToolBar();
         JToolBar toolBar4 = new JToolBar();
         JToolBar toolBar5 = new JToolBar();
         JToolBar toolBar6 = new JToolBar();
         JToolBar toolBar7 = new JToolBar();
         JToolBar toolBar8 = new JToolBar();
         JToolBar toolBar9 = new JToolBar();
         JToolBar toolBar10 = new JToolBar();
         JMenu FirstMenu = new JMenu("File");
    FirstMenu.setMnemonic(KeyEvent.VK_F);     
    textArea = new JTextArea(5, 20);
         textArea1 = new JTextArea(2, 15);     
         textArea2 = new JTextArea(2, 15);
         textArea3 = new JTextArea(2, 15);     
         textArea4 = new JTextArea(7, 15);
         textArea5 = new JTextArea(7, 15);     
         textArea6 = new JTextArea(7, 15);
         textArea7 = new JTextArea(7, 15);
         textArea8 = new JTextArea(2, 15);
         textArea9 = new JTextArea(7, 15);
         textArea10 = new JTextArea(2, 15);
         textArea11 = new JTextArea(7, 15);
         textArea12 = new JTextArea(2, 15);
         textArea13 = new JTextArea(7, 15);
         textArea14 = new JTextArea(2, 15);
         textArea15 = new JTextArea(7, 15);
         JScrollPane scrollPane = new JScrollPane(textArea);
         progressBar=new JProgressBar();
         progressBar.setStringPainted(true);     
    contentPane.setLayout(new GridLayout(2,3));
         JPanel panel1 = new JPanel();
         panel1.setLayout(new BorderLayout());
         panel1.setBackground(Color.blue);
         contentPane.add(panel1);
    panel1.add(BorderLayout.NORTH, toolBar);
         panel1.add(scrollPane, BorderLayout.CENTER);
         panel1.add(progressBar,BorderLayout.SOUTH);     
         JPanel panel2 = new JPanel();     
         JLabel statusBar= new JLabel();
         panel2.setLayout(new GridLayout(1,1));     
         panel2.setBackground(Color.gray);     
         contentPane.add(panel2);
         JPanel panel3 = new JPanel();
         panel3.setLayout(new GridLayout(1,1));     
         panel3.setBackground(Color.blue);
         panel2.add(panel3);
         JPanel panel7 = new JPanel();
         panel7.setLayout(new BorderLayout());     
         panel7.setBackground(Color.blue);
         panel7.add(textArea2, BorderLayout.NORTH);     
         panel7.add(BorderLayout.CENTER, toolBar2);
         panel7.add(BorderLayout.SOUTH, textArea4);
         panel3.add(panel7);
         JPanel panel8 = new JPanel();
         panel8.setLayout(new BorderLayout());     
         panel8.setBackground(Color.blue);
         panel8.add(textArea3, BorderLayout.NORTH);     
         panel8.add(BorderLayout.CENTER, toolBar3);
         panel8.add(BorderLayout.SOUTH, textArea5);
         panel3.add(panel8);
         JPanel panel5 = new JPanel();
         panel5.setLayout(new BorderLayout());
         panel5.add(textArea1, BorderLayout.NORTH);
         panel5.add(BorderLayout.CENTER, toolBar5);
         panel5.add(BorderLayout.SOUTH, textArea7);          
         panel5.setBackground(Color.blue);
         panel3.add(panel5);
         JPanel panel6 = new JPanel();
         panel6.setLayout(new BorderLayout());
         panel6.add(toolBar1, BorderLayout.NORTH);          
         panel6.setBackground(Color.blue);
         panel6.setSize(new Dimension(5,5));
         panel6.add(BorderLayout.CENTER, toolBar4);
         panel6.add(BorderLayout.SOUTH, textArea6);
         panel3.add(panel6);
         JPanel panel4 = new JPanel();
         panel4.setLayout(new GridLayout(1,1));
         panel4.setBackground(Color.blue);     
         panel2.add(panel4);
         JPanel panel9 = new JPanel();
         panel9.setLayout(new BorderLayout());     
         panel9.setBackground(Color.blue);
         panel9.add(textArea8, BorderLayout.NORTH);     
         panel9.add(BorderLayout.CENTER, toolBar6);
         panel9.add(BorderLayout.SOUTH, textArea9);
         panel4.add(panel9);
         JPanel panel10 = new JPanel();
         panel10.setLayout(new BorderLayout());     
         panel10.setBackground(Color.blue);
         panel10.add(textArea10, BorderLayout.NORTH);     
         panel10.add(BorderLayout.CENTER, toolBar7);
         panel10.add(BorderLayout.SOUTH, textArea11);
         panel4.add(panel10);
         JPanel panel11 = new JPanel();
         panel11.setLayout(new BorderLayout());
         panel11.add(textArea12, BorderLayout.NORTH);
         panel11.add(BorderLayout.CENTER, toolBar8);
         panel11.add(BorderLayout.SOUTH, textArea13);          
         panel11.setBackground(Color.blue);
         panel4.add(panel11);
         JPanel panel12 = new JPanel();
         panel12.setLayout(new BorderLayout());
         panel12.add(toolBar9, BorderLayout.NORTH);          
         panel12.setBackground(Color.blue);
         panel12.setSize(new Dimension(5,5));
         panel12.add(BorderLayout.CENTER, toolBar10);
         panel12.add(BorderLayout.SOUTH, textArea15);
         panel4.add(panel12);
         //contentPane.setMaximumSize(new Dimension(600, 400));
         /*contentPane.setLayout(new BorderLayout());
         contentPane.setPreferredSize(new Dimension(400, 150));
         contentPane.add(toolBar, BorderLayout.NORTH);     
    statusBar = new JLabel(" ");     
         contentPane.add(scrollPane, BorderLayout.CENTER);
         setContentPane(contentPane);*/     
         JMenuBar mb = new JMenuBar();
         setJMenuBar(mb);
    mb.add(FirstMenu);     
    menuItem = new JMenuItem("Quick connect", KeyEvent.VK_Q);
    FirstMenu.add(menuItem);
         JMenu SecondMenu = new JMenu("Edit");
         SecondMenu.setMnemonic(KeyEvent.VK_E);     
    menuItem = new JMenuItem("Suspend", KeyEvent.VK_S);
    SecondMenu.add(menuItem);
    mb.add(SecondMenu);
    JMenu ThirdMenu = new JMenu("Compress");
         ThirdMenu.setMnemonic(KeyEvent.VK_C);     
    menuItem = new JMenuItem("By Percentage", KeyEvent.VK_B);
    ThirdMenu.add(menuItem);
    mb.add(ThirdMenu);
    JMenu FourthMenu = new JMenu("Help");
         FourthMenu.setMnemonic(KeyEvent.VK_H);     
    menuItem = new JMenuItem("Help", KeyEvent.VK_B);
    FourthMenu.add(menuItem);
    mb.add(FourthMenu);
    ImageIcon QuickConnect=new ImageIcon("images/Q_connect.gif");
    JButton button=new JButton(QuickConnect);
    button.setActionCommand("QuickConnect");
    button.setToolTipText("Quick Connect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Reconnect=new ImageIcon("images/Reconnect.gif");
    button=new JButton(Reconnect);
    button.setActionCommand("Reconnect");
    button.setToolTipText("Reconnect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Disconnect=new ImageIcon("images/Disconnect.gif");
    button=new JButton(Disconnect);
    button.setActionCommand("Disconnect");
    button.setToolTipText("Disconnect");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Upload=new ImageIcon("images/Upload.gif");
    Button=new JButton(Upload);
    Button.addActionListener(new ActionListener()
    public void actionPerformed(ActionEvent ae)
    String strCommand=ae.getActionCommand();
    if(str.equals("Upload"))
    /* this is where you write the code to call that servlet.
    control reaches this point when the button is pressed */
    try{
    // you communicate with the servlet here
    url = new URL("http://127.0.0.1:7001/servletUpload");
    in = new BufferedReader(new InputStreamReader(url.openStream()));
    str = in.readLine();
    in.close();
    }//end try
    catch (Exception e1){}
    toolBar.add(Button);
    ImageIcon Suspend=new ImageIcon("images/Suspend.gif");
    Button1=new JButton(Suspend);
    //Button1.setActionCommand("Suspend");
    Button1.setToolTipText("Suspend");
    Button1.addActionListener(this);
    toolBar.add(Button1);
    ImageIcon Refresh=new ImageIcon("images/Refresh.gif");
    button=new JButton(Refresh);
    button.setActionCommand("Refresh");
    button.setToolTipText("Refresh");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon DeleteItem=new ImageIcon("images/DeleteItem.gif");
    button=new JButton(DeleteItem);
    button.setActionCommand("DeleteItem");
    button.setToolTipText("DeleteItem");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Resume=new ImageIcon("images/Resume.gif");
    Button2=new JButton(Resume);
    //button.setActionCommand("Resume");
    Button2.setToolTipText("Resume");
    Button2.addActionListener(this);
    toolBar.add(Button2);
    ImageIcon FilePriority=new ImageIcon("images/FilePriority.gif");
    button=new JButton(FilePriority);
    button.setActionCommand("FilePriority");
    button.setToolTipText("FilePriority");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon View=new ImageIcon("images/View.gif");
    button=new JButton(View);
    button.setActionCommand("View");
    button.setToolTipText("View");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Rename=new ImageIcon("images/Rename.gif");
    button=new JButton(Rename);
    button.setActionCommand("Rename");
    button.setToolTipText("Rename");
    button.addActionListener(this);
    toolBar.add(button);
    ImageIcon Scrolling=new ImageIcon("images/left.gif");
    button=new JButton(Scrolling);
    button.setActionCommand("Scrolling");
    button.setToolTipText("Scrolling");
    button.addActionListener(this);
    toolBar1.add(button);
    ImageIcon UScrolling=new ImageIcon("images/right.gif");
    button=new JButton( UScrolling);
    button.setActionCommand(" UScrolling");
    button.setToolTipText("UScrolling");
    button.addActionListener(this);
    toolBar1.add(button);
    ImageIcon Name=new ImageIcon("images/Name.gif");
    button=new JButton( Name);
    button.setActionCommand("Name");
    button.setToolTipText("Name");
    button.addActionListener(this);
    toolBar2.add(button);
    ImageIcon Date=new ImageIcon("images/Date.gif");
    button=new JButton( Date);
    button.setActionCommand("Date");
    button.setToolTipText("Date");
    button.addActionListener(this);
    toolBar3.add(button);
    ImageIcon Time=new ImageIcon("images/Time.gif");
    button=new JButton( Time);
    button.setActionCommand("Time");
    button.setToolTipText("Time");
    button.addActionListener(this);
    toolBar4.add(button);
    ImageIcon Size=new ImageIcon("images/Size.gif");
    button=new JButton(Size);
    button.setActionCommand("Size");
    button.setToolTipText("Size");
    button.addActionListener(this);
    toolBar5.add(button);
    ImageIcon TScrolling=new ImageIcon("images/left.gif");
    button=new JButton(TScrolling);
    button.setActionCommand("TScrolling");
    button.setToolTipText("TScrolling");
    button.addActionListener(this);
    toolBar9.add(button);
    ImageIcon DScrolling=new ImageIcon("images/right.gif");
    button=new JButton( DScrolling);
    button.setActionCommand(" DScrolling");
    button.setToolTipText("DScrolling");
    button.addActionListener(this);
    toolBar9.add(button);
    ImageIcon Name1=new ImageIcon("images/Name.gif");
    button=new JButton( Name1);
    button.setActionCommand("Name1");
    button.setToolTipText("Name1");
    button.addActionListener(this);
    toolBar6.add(button);
    ImageIcon Date1=new ImageIcon("images/Date.gif");
    button=new JButton( Date1);
    button.setActionCommand("Date1");
    button.setToolTipText("Date1");
    button.addActionListener(this);
    toolBar7.add(button);
    ImageIcon Time1=new ImageIcon("images/Time.gif");
    button=new JButton( Time1);
    button.setActionCommand("Time1");
    button.setToolTipText("Time1");
    button.addActionListener(this);
    toolBar10.add(button);
    ImageIcon Size1=new ImageIcon("images/Size.gif");
    button=new JButton(Size1);
    button.setActionCommand("Size1");
    button.setToolTipText("Size1");
    button.addActionListener(this);
    toolBar8.add(button);
    public void actionPerformed(ActionEvent e)
    textArea.setText(e.getActionCommand());
    public static void main(String[] args) {
    ActionDemo1 frame = new ActionDemo1();
    frame.pack();
    frame.setSize(new Dimension(650, 400));
    frame.setVisible(true);
    Regards
    Bikash

    You may find this suggestion useless, but I thnk you should seriously consider tossing your IDE in the trash and getting a good text editor and hand coding Swing until you understand how Swing components work.
    Take shortcuts when you understand where they will lead. You will find that hand coding really leads to a deeper understanding of any programming language.
    While you're at it, why don't you consider whether you really need eleven (!) toolbars in your GUI. A GUI generally needs only one toolbar -- save some for later.

  • Help please with JFRAMES swing  and variables

    Hi...I need some help with Swing.I need to use the variable "datauser" and read it to operate with it( add,multiply,etc)
    I have two independants JFrames.(2 classes in different .java files).
    //FRAME1 get user data
    import javax.swing.JPanel;
    import javax.swing.JTextField;
    import javax.swing.*;
    public class FRAME1 extends javax.swing.JFrame {
              public double datauser; //i need this variable
              public JPanel jPanel1;
              public JTextField jTextField1;
              public FRAME1(){
              datauser=this.datauser;
              jPanel1 = new JPanel();
         jTextField1 = new JTextField();
              jTextField1.setText("10");
              JPanel1.add(jTextField1);
              jTextField1.addActionListener(new hearme());
              pack();
    class hearme implements ActionListener{
    public void actionPerformed(ActionEvent e)
    {     datauser= Double.parseDouble(jTextField1.getText()); //people write a number
    In other JFrame class (another .java file) i put:
    public class FRAME2 extends javax.swing.JFrame
              double aux;
              double multiplyby100() {
              aux= datauser *100;
              return aux;
    ANd i cant get anything just errors ..how can i relate to variables from differents Jframes?? I mean..how can i use a variable from Jframe1 in Jframe2. The actual value that people type in that textfield

    oh well thx for ur help...
    I meant ..i have 10 differentes Jframes (10 different clases)
    SO i have 10 differents windows...Then with a combobox ill choose what Jframe will appear.When a window appears i put ,for instance,parameters for calculating a circle area .Then i select rectangle in the combobox list and appear in the principal window its parameters to write in. Then i choose another element in that combobox and i put parameters for a square.Each one is a different window.I dont want to use Jdialog for that.
    The problem is that i want to use a variable defined in one frame to use that value in another class....for example i want to use a variable like this
    double side =double.parse(Textfield.getText()); //in a texfield in frame 1
    And do something with "side" but in a different class.(different file in the same package)
    public class hi() {
    double theside;
    theside=side; //<---------- here i have problems
    //how can i use the variable "side" in the class hi
    The exact point is that i want to get all the parameters from the user for each window that appears.And each class Jframe have their own variables .
    And i want to access to those variables in real time (what people type)
    So i cant find any solution.I have a structure for each window with labels and textfields (to put parameters).And i need to save each variable that people type in those textfields in public variables because i need to operate with data in a different class (for example in a main class).But that data is only saved into the particular classes because variables exist in there.
    Thanks in advance for ur answers .I havent slept for hours trying to think of that
    thanks!

  • Help for a java swing

    I created a Swing application and I have to add a help menu (a standard help like the one any Windows application has).
    Any suggestions,
    Thanks

    This I know.
    But what are the classes I have to use in order to create and display the help as the one you have in IE, for example.
    Press F1 to any application and you will understand what I mean

  • Help needed new to swing

    Hi,
    First of all sorry if this particular post is in wrong forum but since my coding is done using swing and AWT i am posting this in swing forum.
    Coming to my question I have made a GUI ( Tool) using swing components and my complete java file is called as MainWindow.java .. and there is no problem with code its working fine.
    NOTE: I have taken help form 74philip, uhrand, dek dilirium, camkcir to generate this code..
    Nowmy question is i want to place my GUi in my university server so that i have to make a link and place in my university webpage so that when i click that link my program should get compiled and executed.
    How can i make a link ( say name that link as Measurement Tool) so that when i click that link my program should get Executed....?
    Thanks in advance

    example steps create a jar file that uses a few different files from an app created with NetBeans:
    C:\javalibs>jar cmf mymanifest.txt myapp.jar *.class myform.form
    example manifest file:
    Class-Path: lib/AbsoluteLayout.jar lib/commons-logging.jar lib/itext-1.02b.jar lib/jasperreports-0.6.4.jar lib/ojdbc14.jar
    Main-Class: MyForm
    If I remember correctly, the class-path isn't needed here when your using web start, just the main-class.
    example JNLP file:
    <?xml version="1.0" encoding="utf-8"?>
    <!-- JNLP File for Simple Application -->
    <jnlp
    codebase="http://net1/app/"
    href="app.jnlp">
    <information>
    <title>Data Entry</title>
    <vendor>Company Name</vendor>
    <description>DATA ENTRY</description>
    <description kind="short">DATA </description>
    <offline-allowed/>
    </information>
    <resources>
    <j2se version="1.5"/>
    <jar href="myapp.jar"/>
    </resources>
    <application-desc main-class="MyForm"/>
    </jnlp>
    Hope that helps,
    Alan

  • Need help with  HTML and Swing Components

    Dear All,
    I am using HTML text for Jbutton and Jlabel and MenuItem.
    But when i am trying to disable any of these, its foreground color is not being grayed out.
    For that, I have overrided the setEnable() method as mentioned below:
    import java.awt.*;
    import java.awt.event.MouseEvent;
    import java.awt.event.MouseListener;
    import java.awt.event.WindowAdapter;
    import java.awt.event.WindowEvent;
    import javax.swing.*;
    import javax.swing.plaf.FontUIResource;
    * HtmlLabelEx.java
    public class HtmlLabelEx extends javax.swing.JDialog implements MouseListener{
         * Creates new form HtmlLabelEx
        public HtmlLabelEx(java.awt.Frame parent, boolean modal) {
            super(parent, modal);
            UIManager.put("swing.boldMetal", Boolean.FALSE);
            initComponents();
            setLayout(null);
            this.addWindowListener(new WindowAdapter()
                public void windowClosing(WindowEvent event)
                    System.exit(0);
            JLabel jLabel1 = new JLabel()
                public void setEnabled(boolean b)
                  super.setEnabled(b);
                  setForeground(b ? (Color) UIManager.get("Label.foreground") : (Color) UIManager.get("Label.disabledForeground"));
            JButton jButton1 = new JButton()
                public void setEnabled(boolean b)
                  super.setEnabled(b);
                  setForeground(b ? (Color) UIManager.get("Label.foreground") : (Color) UIManager.get("Label.disabledForeground"));
            add(jButton1);
            String str = "<html><body><b>Label</b></body></html>";
            System.out.println("str = "+str);
        jLabel1.setText(str);
        add(jLabel1);
        jLabel1.setBounds(10,10,100,20);
        jLabel1.setEnabled(false);
        jButton1.setText("<html><body><b>Button</b></body></html>");
        jButton1.setEnabled(true);
        jButton1.setBounds(10,50,100,20);
        System.out.println("getText = "+jLabel1.getText());
        setSize(400,400);
        addMouseListener(this);
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
        // <editor-fold defaultstate="collapsed" desc=" Generated Code ">                         
        private void initComponents() {
            getContentPane().setLayout(null);
            setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
            pack();
        }// </editor-fold>                       
         * @param args the command line arguments
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new HtmlLabelEx(new javax.swing.JFrame(), true).setVisible(true);
        // Variables declaration - do not modify                    
        // End of variables declaration                  
        public void mouseClicked(MouseEvent e)
            if(e.getButton() == e.BUTTON3)
                JMenuItem mit = new JMenuItem("<html><body><b>Menu Item</b></body></html>");
                JPopupMenu pop = new JPopupMenu();
                pop.add(mit);
                mit.setEnabled(false);
                pop.show(this,e.getX(),e.getY());
        public void mousePressed(MouseEvent e) {
        public void mouseReleased(MouseEvent e) {
        public void mouseEntered(MouseEvent e) {
        public void mouseExited(MouseEvent e) {
    But, I think it is difficult to write like this for each component.
    I am looking for an optimized solution so that the change will be only in one place.
    so that, It wont leads to change so many pages or so many places.
    And i have the following assumptions to do this. please let me know the possibility.
    1.Implementing custom UI class, extending the JButton/JMenuItem (As the BasicButton/MenuItemUI class does not have setEnabled() method to override) and putting this in UIManager.put("ButtonUI/MenuItemUI","CustomClass).
    2.If there is any possibility to achieve this, by just overriting any key in the UIManager
    3.By setting any client property globally.
    My requirement is to do this only at one place for entire the application.So, that we need not change all the buttoins, sya some 30 buttions are there in a dialog, then we need to override each button class.
    Please suggest me the possibilties..
    Thank you

    Hi camickr ,
    I know that to set the font we have to use component.setfont().
    But, as per my requirement,i am not setting any font to any component in my application.
    i am just passing HTML text along with FONT tags to all the components in my Application.SO, in this case we will get bold letters and that problem fixed when we set swing.boldMetal = false in UI Manager.
    But actual problem irrespective of font settings is when ever we use HTML rendered text, when the button or menuitem is disabled,then that one will not be changed to gray color. i.e., it still looks like normal controls, even it is disabled.(It is also reported as bug)
    But, as per my knowledge we can fix by overrding setEnabled or paint() methods for each and every component.
    But, if we do like that, for an application that has 200 buttons or MenuItems, it is difficult to follow that approach.
    So, We should find a way to achieve that only in one place like using UIManager or other one as i mentioned in previous posts if possible.
    I hope you understood what my problem is exactly.
    Thank You
    Edited by: sindhumourya on Mar 4, 2010 7:26 AM

  • Help: Design Issues in Swing

    Hi Friends
    I developed an application in swings way back in 2000-01. However then there were serious issues of Memory leakage with Swings. Hence the strategy we adopted was to use a cache of Swing components rather than creating new objects everytime.
    Now again in 2004, i am back to swings.
    Now are there still issues with the swings?
    What are the other things, we need to keep in mind during the design?
    I heard that listeners create problem with the components since component get registered with the Listeners and are not able to get released.
    And there are problems of lot of internal objects being created.. Is this true.. if yes.. how do we tackle the problem??

    hi,
    I'm using swing in some programs of my own, and I've not experienced any serious problems yet.
    Some points need to be mentioned however:
    - Instantiating heavyweight components (such as JFileChooser) tends to be slow, try instantiating only one JFileChooser for your application and reuse it by just hiding/showing it.
    - Most programs instantiate all their components (visible and invisible) at startup. This slows down the startup time and the performance feeling of your program. Try using lazy-instantiation (do not initialise the component at the beginning but only initialise the component when it is called upon for the first time). Some more specific instantiation-schemes can be used, for instance for image- or sound-loading.
    Of course the splash-screen with small animations tends to ease the pain to wait for the user.
    - caching can also be used to improve performance, but here I think you should always first measure the performance of the component to be cached (using a profiler). Using a cache on a well performing object might also reduce it's performance.
    To reduce the memory-footprint of the cache, you could combine it with the lazy-instantiation and perhaps even use WeakReferences to hold this objects in order not to let the cache be a memory-bottleneck.
    This can be especially useful when using large quantities of equal objects (what also happens for String) or when using a decent amount of very memory-consuming objects such as images.
    Normally (for the remaining optimization) it is adviced to not optimize while programming, and only start to optimize for performance and memory usage when problems show up. For doing this you should use some serious profiler, instead of blindly optimizing what seems slow.
    Also try reading the book about java performance which can be found using the link below:
    http://java.sun.com/docs/books/performance/1st_edition/html/JPTOC.fm.html
    This book gives many of the advices I've given above and explains the total process of performance-tuning. Another advantage of this book is that it uses Swing as an example for it's optimizations, and that the author has cooperated in programming (parts of) Swing.
    Kind regards,
    Koen

  • Need help with threading in Swing GUI !!!

    I've written an app that parses and writes
    files. I'm using a Swing GUI. The app
    could potenially be used to parse hundreds or even
    thousands of files. I've included a JProgressBar
    to monitor progress. The problem is when I parse
    a large number of files the GUI freezes and only
    updates the values of the progress bar when the
    parsing and writing process is finished.
    I assume I need to start the process in a seperate thread. But, I'm new to threads and I'm not sure
    whether to start the Progressbar code in a seperate
    thread or the parsing code. As a matter of fact I really
    don't have any idea how to go about this.
    I read that Swing requires repaints be done in the
    event dispatch thread. If I start the parsing in a seperate
    thread how do I update the progressbar from the other
    thread? I'm a thread neophyte.
    I need a cigarette.

    In other words do this:
    Inside event Thread:
    handle button action
    start thread
    return from action listener
    Inside worker Thread:
    lock interface
    loop
    perform action
    update progress bar
    unlock interface
    return from worker ThreadDoesn't updating the progress bar (and locking/unlocking the interface components) from within the worker thread violate the rule that you shouldn't mess with Swing components outside the event thread? (Do I have that rule right?)
    In any case, is there any way to just post some kind of event to the progress bar to update it from within the worker thread, thereby insuring that the GUI progress bar update is being invoked from the event thread? This would also obviate the need to use a timer to poll for an update, which I think is a waste especially when the monitored progress is at a variable rate, (or for number crunching, is executing on different speed machines).
    Also, doesn't using invokeLater() or invokeAndWait() still block the event dispatching thread? I don't understand how having a chunk of code started in the event thread doesn't block the event thread unless the code's executed in a "sub-thread", which would then make it not in the event thread.
    I'm also looking to have a progress bar updated to monitor a worker thread, but also want to include a "Stop" button, etc. and need the event queue not to be blocked.
    The last thing I can think of is to implement some kind of original event-listener class that listens to events that I define, then register it with the system event queue somehow, then have the worker thread post events to this listener which then calls setValue() in the progress bar to insure that the bar is updated from the event queue and when I want it to be updated. I don't know yet if it's possible to create and register these kinds of classes (I'm guessing it is).
    Thanks,
    Derek

  • Help to solve a swing problem

    Hi,
    I have to add a mouse over event and mouse click event in my rectangles that I draw while taking the values from an input file. Now since I am taking rectangle height and width from the input text file as well I also want to take a text value to be shown while moving a mouse over a particular rectangle from my input file. Also when user clicks on that rectangle the height and width of that particular rectangle only should be displayed (re-adjusted).
    Now When my paint component draws these 2 rectangles and a user moves his mouse over the rectangle he should see text message attached to it:- Like for first row 10, 23 he should see "Hello". In this case when he clicks on this rectangle the picture should read just to show only 10 and 20 as height and width.
    I am trying to write 2 classes. 1st one extends JPanel and the other one MouseInputAdapter.
    Here is the input file example below:-
    Height   Width  Test_To_Show   Colors
    10          23         Hello        300
    20          44         Bye          000Here is my attempted code but still not getting what I want :(
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.BufferedReader;
    import java.util.List;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Color;
    import javax.swing.JFrame;
    import java.awt.geom.Rectangle2D;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class MousingExample extends JPanel {
        List<String> tips;
        JWindow toolTip;
        JLabel label;
        public String f[];
      public MousingExample(Frame f)
            tips = new ArrayList<String>();
            tips.add("Lets Start The Show");
            toolTip = new JWindow(f);
            label = new JLabel();
            label.setHorizontalAlignment(JLabel.CENTER);
            label.setOpaque(true);
            label.setBackground(UIManager.getColor("MousingExample.background"));
            label.setBorder(UIManager.getBorder("MosusingExample.border"));
            toolTip.add(label);
            setOpaque(true);
        public ArrayList<Rectangle> rects = new ArrayList<Rectangle>();
        public int width;
        public String color;
        public static int score;
        public static int value1;
        public static int value2;
        private final static int NUM_FIELDS = 4;
        public void InputReader() {
            String n = null; 
            try{
                BufferedReader fh = new BufferedReader(new FileReader("inputfile.txt"));   
                while((n = fh.readLine()) != null && (n = n.trim()).length() > 0){
                   // System.out.println(n);
                    f = n.split("\t");
                    int height = Integer.parseInt(f[0].trim());
                    int width = Integer.parseInt(f[1].trim());
                    String message = f[2];
                    Color color = new Color(Integer.parseInt(f[3]));
                    Rectangle tempLineInfo = new Rectangle(color, value1, value2, width);
                    rects.add(tempLineInfo);
                fh.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e2) {
                e2.printStackTrace();
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            setBackground(Color.white);
            for(int i=0; i<rects.size(); i++){
                Rectangle c = rects.get(i);
                GradientPaint gpi = new GradientPaint(0, 0,c.getColor() , 0, 20, Color.white, true);
                g2d.setPaint(gpi);
                g2d.drawRect(c.value1, 20, c.width, 35);
                g2d.fillRect(c.value1, 20, c.width, 35);
                System.out.printf("Drawing at %s\n", c);
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            MousingExample test = new MousingExample(frame);
            test.InputReader();
            Tipster tipster = new Tipster(test);
            test.addMouseListener(tipster);
            test.addMouseMotionListener(tipster);
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setTitle("Trying To MouseOver");
            frame.setSize(400, 400);
            frame.setContentPane(test);
            frame.setVisible(true);
    class Rectangle {
        private Color color;
        public int value1;
        public int value2;
        public int width;
        public Rectangle(Color c, int value1, int value2, int width){
            this.color = c;
            this.value1 = value1;
            this.value2 = value2;
            this.width = width;
        public Color getColor(){
            return color;
        public String toString() {
            return String.format("Color=%s,top=%d,bottom=%d,width=%d", color.toString(), value1, value2, width);
    class Tipster extends MouseInputAdapter
        MousingExample Mousing;
        Point start;
        public Tipster(MousingExample tt)
            Mousing = tt;
        public void mousePressed(MouseEvent e) { }
        public void mouseReleased(MouseEvent e) { }
        public void mouseDragged(MouseEvent e) { }
        public void mouseMoved(MouseEvent e)
            List<Rectangle> rects = MousingExample.Rectangle;
            //Not Sure what I should do here
    }Thanks in adavnce
    Sheikh Chilly :)

    Ok I will try to work more on your advice. This is my code so far after some more modifications. Plz do lemme know where I am making mistakes. Anyway thanks for guiding me.
    import java.io.*;
    import java.util.ArrayList;
    import java.util.Arrays;
    import java.io.File;
    import java.io.FileNotFoundException;
    import java.io.BufferedReader;
    import java.util.List;
    import java.awt.*;
    import javax.swing.*;
    import java.awt.Color;
    import javax.swing.JFrame;
    import java.awt.geom.Rectangle2D;
    import java.awt.Container;
    import java.awt.Dimension;
    import java.awt.Graphics;
    import javax.swing.event.*;
    import java.awt.event.*;
    import java.awt.event.MouseListener;
    import java.awt.event.MouseEvent;
    public class MouseExample extends JPanel {
        List<String> tips;
        JWindow toolTip;
        JLabel label;
        public String f[];
      public MouseExample(Frame f)
            tips = new ArrayList<String>();
         //   tips.add("Lets Start The Show");
            toolTip = new JWindow(f);
            label = new JLabel();
            label.setHorizontalAlignment(JLabel.CENTER);
            label.setOpaque(true);
            label.setBackground(UIManager.getColor("MouseExample.background"));
            label.setBorder(UIManager.getBorder("MosusingExample.border"));
            toolTip.add(label);
            setOpaque(true);
        public ArrayList<Rectangle> rects = new ArrayList<Rectangle>();
        public int width;
        public String color;
        public static int score;
        public static int value1;
        public static int value2;
        private final static int NUM_FIELDS = 4;
        public void InputReader() {
            String n = null; 
            try{
                BufferedReader fh = new BufferedReader(new FileReader("inputfile.txt"));   
                while((n = fh.readLine()) != null && (n = n.trim()).length() > 0){
                   // System.out.println(n);
                    f = n.split("\t");
                    int height = Integer.parseInt(f[0].trim());
                    int width = Integer.parseInt(f[1].trim());
                    String message = f[2];
                    tips.add(message);
                    Color color = new Color(Integer.parseInt(f[3]));
                    Rectangle tempLineInfo = new Rectangle(color, value1, value2, width);
                    rects.add(tempLineInfo);
                fh.close();
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            } catch (IOException e2) {
                e2.printStackTrace();
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint( RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            setBackground(Color.white);
            for(int i=0; i<rects.size(); i++){
                Rectangle c = rects.get(i);
                GradientPaint gpi = new GradientPaint(0, 0,c.getColor() , 0, 20, Color.white, true);
                g2d.setPaint(gpi);
                g2d.drawRect(c.value1, 20, c.width, 35);
                g2d.fillRect(c.value1, 20, c.width, 35);
                System.out.printf("Drawing at %s\n", c);
          public boolean isToolTipShowing()
            return toolTip.isShowing();
           public void showToolTip(int index, Point p)
            for(index = 0; index<tips.size();index++){
            label.setText(tips.get(index));
            toolTip.pack();
            toolTip.setLocation(p);
            toolTip.setVisible(true);
        public static void main(String[] args) {
            JFrame frame = new JFrame();
            MouseExample test = new MouseExample(frame);
            test.InputReader();
            Tipster tipster = new Tipster(test);
            test.addMouseListener(tipster);
            test.addMouseMotionListener(tipster);
            frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
            frame.setTitle("Trying To MouseOver");
            frame.setSize(400, 400);
            frame.setContentPane(test);
            frame.setVisible(true);
    class Rectangle {
        private Color color;
        public int value1;
        public int value2;
        public int width;
        public Rectangle(Color c, int value1, int value2, int width){
            this.color = c;
            this.value1 = value1;
            this.value2 = value2;
            this.width = width;
        public Color getColor(){
            return color;
        public String toString() {
            return String.format("Color=%s,top=%d,bottom=%d,width=%d", color.toString(), value1, value2, width);
    class Tipster extends MouseInputAdapter
        MouseExample mousing;
        Point start;
        public Tipster(MouseExample tt)
            mousing = tt;
        public void mousePressed(MouseEvent e) { }
        public void mouseReleased(MouseEvent e) { }
        public void mouseDragged(MouseEvent e) { }
        public void mouseMoved(MouseEvent e)
    Point p = e.getPoint();
            boolean traversing = false;
            List<Rectangle> rect = mousing.rects;
            for(int i; i<rect.size() ; i++ ){
                Rectangle r = rect.get(i);
                if(r.contains(p)) {
                  if(!mousing.isToolTipShowing())
                        SwingUtilities.convertPointToScreen(p, mousing);
                        mousing.showToolTip(i, p);
                    traversing = true;
                    break;
    }Thanks
    Sheikh Chilly :)

  • Help needed new to Swing Programming

    Hi,
    I have Crated a JFrame (Frame1) with 4 textfields and a button (by name GetBarchart).
    My question is i will enter some values in 4 textfields and press the GetBarchart button it should display a new JFrame( say Frame2 ) and a Barchart with values taken form the 4 textfields should be displyed.
    NOTE: I should get the BarChart displayed in Frame2 , NOT in Frame1.
    anyhelp is appeciated .
    Thanks in advance

    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.text.DecimalFormat;
    import org.jfree.chart.*;
    import org.jfree.chart.plot.*;
    import org.jfree.data.category.*;
    import org.jfree.ui.*;
    // Make a main window with a top-level menu: File
    public class MainWindow extends JFrame {
        public MainWindow() {
            super("Menu System Test Window");
            setSize(500, 500);
            // make a top level File menu
            FileMenu fileMenu = new FileMenu(this);
            // make a menu bar for this frame
            // and add top level menus File and Menu
            JMenuBar mb = new JMenuBar();
            mb.add(fileMenu);
            setJMenuBar(mb);
            addWindowListener(new WindowAdapter() {
                public void windowClosing(WindowEvent e) {
                    exit();
        public void exit() {
            setVisible(false); // hide the JFrame
            dispose(); // tell windowing system to free resources
            System.exit(0); // exit
        public static void main(String args[]) {
            MainWindow w = new MainWindow();
            w.setVisible(true);
        private static MainWindow w ;
        protected JTextField t1, t2, t3, t4;
        // Encapsulate the look and behavior of the File menu
        class FileMenu extends JMenu implements ActionListener {
            private MainWindow mw; // who owns us?
            private JMenuItem itmPE   = new JMenuItem("ProductEvaluation");
            private JMenuItem itmExit = new JMenuItem("Exit");
            public FileMenu(MainWindow main) {
                super("File");
                this.mw = main;
                this.itmPE.addActionListener(this);
                this.itmExit.addActionListener(this);
                this.add(this.itmPE);
                this.add(this.itmExit);
            // respond to the Exit menu choice
            public void actionPerformed(ActionEvent e) {
                if (e.getSource() == this.itmPE) {
                    JFrame f1 = new JFrame("ProductMeasurementEvaluationTool");
                    f1.setSize(1290,1290);
                    f1.setLayout(null);
                    t1 = new JTextField("0");
                    t1.setBounds(230, 630, 50, 24);
                    f1.add(t1);
                    t2 = new JTextField("0");
                    t2.setBounds(430, 630, 50, 24);
                    f1.add(t2);
                    t3 = new JTextField("0");
                    t3.setBounds(630, 630, 50, 24);
                    f1.add(t3);
                    t4 = new JTextField("0");
                    t4.setBounds(840, 630, 50, 24);
                    f1.add(t4);
                    JLabel l1 = new JLabel("Select the appropriate metrics for Measurement Process Evaluation");
                    l1.setBounds(380, 50, 380, 20);
                    f1.add(l1);
                    JLabel l2 = new JLabel("Architecture Metrics");
                    l2.setBounds(170, 100, 110, 20);
                    f1.add(l2);
                    JLabel l3 = new JLabel("RunTime Metrics");
                    l3.setBounds(500, 100, 110, 20);
                    f1.add(l3);
                    JLabel l4 = new JLabel("Documentation Metrics");
                    l4.setBounds(840, 100, 130, 20);
                    f1.add(l4);
                    JRadioButton rb1 = new JRadioButton("Componenent Metrics",false);
                    rb1.setBounds(190, 140, 133, 20);
                    f1.add(rb1);
                    JRadioButton rb2 = new JRadioButton("Task Metrics",false);
                    rb2.setBounds(540, 140, 95, 20);
                    f1.add(rb2);
                    JRadioButton rb3 = new JRadioButton("Manual Metrics",false);
                    rb3.setBounds(870, 140, 108, 20);
                    f1.add(rb3);
                    JRadioButton rb4 = new JRadioButton("Configuration Metrics",false);
                    rb4.setBounds(190, 270, 142, 20);
                    f1.add(rb4);
                    JRadioButton rb6 = new JRadioButton("DataHandling Metrics",false);
                    rb6.setBounds(540, 270, 142, 20);
                    f1.add(rb6);
                    JRadioButton rb8 = new JRadioButton("Development Metrics",false);
                    rb8.setBounds(870, 270, 141, 20);
                    f1.add(rb8);
                    JCheckBox  c10 = new JCheckBox("Size");
                    c10.setBounds(220, 170, 49, 20);
                    f1.add(c10);
                    JCheckBox c11 = new JCheckBox("Structure");
                    c11.setBounds(220, 190, 75, 20);
                    f1.add(c11);
                    JCheckBox c12 = new JCheckBox("Complexity");
                    c12.setBounds(220, 210, 86, 20);
                    f1.add(c12);
                    JCheckBox c13 = new JCheckBox("Size");
                    c13.setBounds(220, 300, 49, 20);
                    f1.add(c13);
                    JCheckBox c14 = new JCheckBox("Structure");
                    c14.setBounds(220, 320, 75, 20);
                    f1.add(c14);
                    JCheckBox c15 = new JCheckBox("Complexity");
                    c15.setBounds(220, 340, 86, 20);
                    f1.add(c15);
                    JCheckBox c19 = new JCheckBox("Size");
                    c19.setBounds(580, 170, 49, 20);
                    f1.add(c19);
                    JCheckBox c20 = new JCheckBox("Structure");
                    c20.setBounds(580, 190, 75, 20);
                    f1.add(c20);
                    JCheckBox c21 = new JCheckBox("Complexity");
                    c21.setBounds(580, 210, 86, 20);
                    f1.add(c21);
                    JCheckBox c22 = new JCheckBox("Size");
                    c22.setBounds(580, 300, 49, 20);
                    f1.add(c22);
                    JCheckBox c23 = new JCheckBox("Structure");
                    c23.setBounds(580, 320, 75, 20);
                    f1.add(c23);
                    JCheckBox c24 = new JCheckBox("Complexity");
                    c24.setBounds(580, 340, 86, 20);
                    f1.add(c24);
                    JCheckBox c28 = new JCheckBox("Size");
                    c28.setBounds(920, 170, 49, 20);
                    f1.add(c28);
                    JCheckBox c29 = new JCheckBox("Structure");
                    c29.setBounds(920, 190, 75, 20);
                    f1.add(c29);
                    JCheckBox c30 = new JCheckBox("Complexity");
                    c30.setBounds(920, 210, 86, 20);
                    f1.add(c30);
                    JCheckBox c31 = new JCheckBox("Size");
                    c31.setBounds(920, 300, 49, 20);
                    f1.add(c31);
                    JCheckBox c32 = new JCheckBox("Structure");
                    c32.setBounds(920, 320, 75, 20);
                    f1.add(c32);
                    JCheckBox c33 = new JCheckBox("Complexity");
                    c33.setBounds(920, 340, 86, 20);
                    f1.add(c33);
                    ActionListener action = new MyActionListener(f1, t1, t2,t3,t4);
                    JButton b1  = new JButton("Button1");
                    b1.setBounds(230, 600, 120, 24);
                    b1.addActionListener(action);
                    f1.add(b1);
                    JButton b2  = new JButton("Button2");
                    b2.setBounds(430, 600, 120, 24);
                    b2.addActionListener(action);
                    f1.add(b2);
                    JButton b3  = new JButton("Button3");
                    b3.setBounds(630, 600, 120, 24);
                    b3.addActionListener(action);
                    f1.add(b3);
                    JButton b4  = new JButton("Button4");
                    b4.setBounds(840, 600, 120, 24);
                    b4.addActionListener(action);
                    f1.add(b4);
                    JButton b5  = new JButton("Generatechart");
                    b5.setBounds(1040, 600, 120, 24);
                    b5.setBounds(530, 660, 120, 24);//uhrand
                    b5.addActionListener(action);
                    f1.add(b5);
                    f1.addWindowListener(new WindowAdapter() {
                        public void windowClosing(WindowEvent e) {
                            System.exit(0);
                    f1.setVisible(true);
                } else {
                    mw.exit();}
        class MyActionListener implements ActionListener {
            private JFrame     f1;
            private JTextField t1;
            private JTextField t2;
            private JTextField t3;
            private JTextField t4;
            private  final DecimalFormat result = new DecimalFormat("0.0");
            public MyActionListener(JFrame f1, JTextField tf1, JTextField tf2,JTextField tf3,JTextField tf4) {
                this.f1 = f1;
                this.t1 = tf1;
                this.t2 = tf2;
                this.t3 = tf3;
                this.t4 = tf4;
            public void actionPerformed(ActionEvent e) {
                String s = e.getActionCommand();
                if (s.equals("Button1")) {
                    Component[] components = this.f1.getContentPane().getComponents();
                    int numOfCheckBoxes = 81;
                    int numChecked = 0;
                    for (int i = 0; i < components.length; i++)
                        if (components[i] instanceof JCheckBox)
                            if (((JCheckBox)components).isSelected())
    numChecked++;
    double ratio = ((double) numChecked / (double) numOfCheckBoxes)*100;
    this.t1.setText(result.format(ratio) );
    }else if (s.equals("Button2")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+5);
    this.t2.setText(result.format(ratio) );
    }else if (s.equals("Button3")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+10);
    this.t3.setText(result.format(ratio) );
    }else if (s.equals("Button4")) {
    Component[] components = this.f1.getContentPane().getComponents();
    int numOfCheckBoxes = 81;
    int numChecked = 0;
    for (int i = 0; i < components.length; i++)
    if (components[i] instanceof JCheckBox)
    if (((JCheckBox)components[i]).isSelected())
    numChecked++;
    double ratio = (((double) numChecked / (double) numOfCheckBoxes)*100+15);
    this.t4.setText(result.format(ratio) );
    }else if (s.equals("Generatechart")) {
    Bar_Chart barChart = new Bar_Chart("Bar Chart", t1.getText(),t2.getText(),t3.getText(),t4.getText());
    barChart.pack();
    RefineryUtilities.centerFrameOnScreen(barChart);
    barChart.setVisible(true);
    class Bar_Chart extends JDialog {
    String t1,t2,t3,t4;
    public Bar_Chart(String title, String t1, String t2, String t3, String t4) {
    this.t1=t1;
    this.t2=t2;
    this.t3=t3;
    this.t4=t4;
    setModal(true);
    setTitle(title);
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    CategoryDataset dataset = createDataset();
    JFreeChart chart = createChart(dataset);
    ChartPanel chartPanel = new ChartPanel(chart, false);
    chartPanel.setPreferredSize(new Dimension(500, 270));
    setContentPane(chartPanel);
    private CategoryDataset createDataset() {
    String series1 = "First";
    String series2 = "Second";
    String series3 = "Third";
    String series4 = "Fourth";
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    dataset.addValue(Double.parseDouble(t1.replace(',','.')), series1, "");
    dataset.addValue(Double.parseDouble(t2.replace(',','.')), series2, "");
    dataset.addValue(Double.parseDouble(t3.replace(',','.')), series3, "");
    dataset.addValue(Double.parseDouble(t4.replace(',','.')), series4, "");
    return dataset;
    private static JFreeChart createChart(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart(
    "Bar Chart", // chart title
    "Category", // domain axis label
    "Value", // range axis label
    dataset, // data
    PlotOrientation.VERTICAL, // orientation
    true, // include legend
    true, // tooltips?
    false // URLs?
    return chart;

  • Urgently need some help with a few Swing questions

    Hi
    I'm hoping someone can help me, I need to get these problems fixed very soon or I'm in trouble.
    Scenario: I have a JTreeTable inside a JScrollPane inside a JPanel that is inside a JFrame.
    Problems I'm having (solutions or help with any of all would be greatly appreciated):
    1. I'm trying to make it possible to do a selection in the JTreeTable by right-clicking the mouse (as well as the normal left click), but only if there is nothing currently selected, so I do something like this:
            int[] sel = treeTable.getSelectedRows();
            if ((sel == null) || (sel.length == 0)) {
                treeTable.setColumnSelectionAllowed(false);
                treeTable.setRowSelectionAllowed(true);
                treeTable.setRowSelectionInterval(0, 0);            // but I don't know what these values should be set to, where to get them from?
            }I want to select the row at the mouse cursor, I have the x/y values but I don't know how to relate them to the row index. The full feature that I require is I need
    2. I have a popup menu that appears after a right click on the JTreeTable, it's handled by a MouseListener attached to the JTreeTable, I want this to also appear anywhere else in the JScrollpane. I've tried moving the MouseListener to the JScrollPane, but then the popup stops working if user clicks inside JTreeTable, if I add it to both, it almost works, except that user cannot click below the JTreeTable's first column. Any ideas on this?
    3. How can I change the JTreeTable selection behaviour so that you can only multi-select using Ctrl/Shift and not the mouse? Mouse must only allow single connection, I'm currently using:
    treeTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);But this allows mouse drag selection as well, which shouldn't be there. How is this avoidable?
    4. I want to make the minimize button to make an icon in system tray and be able to restore it by clicking on it. Also I want to be able to minimze from a popup menu, I've currently got the following:
            thisApp.getMainFrame().setState(Frame.ICONIFIED);
            thisApp.getMainFrame().setVisible(false);
            thisApp.getMainFrame().pack();
            try {
               tray.add(trayIcon);
            } catch (AWTException ex) {
            }thisApp is a copy of the SingleFrameApplication variable that is passed to the main frame constructor (main frame extends FrameView). This code above doesn't do anything except create the tray icon. If I click on the tray icon (code below) then it opens up a blank window:
            trayIcon.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    thisApp.getMainFrame().setVisible(true);
                    thisApp.getMainFrame().setState(Frame.NORMAL);
                    thisApp.getMainFrame().pack();
                    tray.remove(trayIcon);
            });I need to get this part fixed and I optionally also want to bind this behaviour to the normal minimize button.
    Please, please help!
    Lionel

    Issue 2 has been solved, was an error in the MouseListener code.

  • Help - Why don't swing applet print, like awt applets do?

    I am using JTable in a applet, but I would like to be able to print the applet using microsoft explorer. I had written a bulkier version of the same applet using an array of TextFields to establish a Table effecte. The code is bulking and loads slow in the browser. JTables work better but the applet shows up all black when I try and print it. What do I do to fix the problem? Do I have to use TextField if I want to print it? Any suggestions would be helpfull.

    While waiting I dug deeper into the bugged section of code and found that:
    divider.setBounds(0,62,600,2);
    was the problem, and that:
    divider.setBounds(0,62,600,4);
    works.
    Don't ask me why I couldn't tell you, but IE 6 doesn't like the heigth to be less than 4. If it is the entire applet prints out black.

Maybe you are looking for