Using setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH); ...?

using setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
JFrame Window will cover windows toolbar.
how to create JFrame,make it max size,don't cover windows toolbar.

import javax.swing.*;
import java.awt.*;
class Testing
  public void buildGUI()
    JFrame f = new JFrame();
    f.setExtendedState(JFrame.MAXIMIZED_BOTH);
    GraphicsEnvironment env = GraphicsEnvironment.getLocalGraphicsEnvironment();
    f.setMaximizedBounds(env.getMaximumWindowBounds());
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.setVisible(true);
  public static void main(String[] args)
    SwingUtilities.invokeLater(new Runnable(){
      public void run(){
        new Testing().buildGUI();
}

Similar Messages

  • Variable textArea not found in class javax.swing.JFrame...

    Making progress on this issue -- but still stuck. Again trying to get the text from a JTextArea on exit:
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
                System.out.println("Why me???" + frame.textArea.getText());
            });User MARSIAN helped me understand the scope fo the variables and now that has been fixed. Unfortunately I cannot access my variable textArea in the above code. If get this error:
    Error: variable textArea not found in class javax.swing.JFrame
    What am I doing wrong?
    import  java.net.*;
    import  javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import FragImpl.*;
    public class Framework extends WindowAdapter {
        public int numWindows = 0;
        private Point lastLocation = null;
        private int maxX = 500;
        private int maxY = 500;
        JFrame frame;
        public Framework() {
            newFrag();
            Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
            maxX = screenSize.width - 50;
            maxY = screenSize.height - 50;
            makeNewWindow();
        public void makeNewWindow() {
            frame = new MyFrame(this);  //*
            numWindows++;
            System.out.println("Number of windows: " + numWindows);
            if (lastLocation != null) {
                //Move the window over and down 40 pixels.
                lastLocation.translate(40, 40);
                if ((lastLocation.x > maxX) || (lastLocation.y > maxY)) {
                    lastLocation.setLocation(0, 0);
                frame.setLocation(lastLocation);
            } else {
                lastLocation = frame.getLocation();
            System.out.println("Frame location: " + lastLocation);
            frame.setVisible(true);
            frame.addWindowListener
           (new WindowAdapter() {
             public void windowClosing(WindowEvent e)
                System.out.println("Why me???" + frame.textArea.getText());
        //This method must be evoked from the event-dispatching thread.
        public void quit(JFrame frame) {
            if (quitConfirmed(frame)) {
                System.exit(0);
            System.out.println("Quit operation not confirmed; staying alive.");
        private boolean quitConfirmed(JFrame frame) {
            String s1 = "Quit";
            String s2 = "Cancel";
            Object[] options = {s1, s2};
            int n = JOptionPane.showOptionDialog(frame,
                    "Windows are still open.\nDo you really want to quit?",
                    "Quit Confirmation",
                    JOptionPane.YES_NO_OPTION,
                    JOptionPane.QUESTION_MESSAGE,
                    null,
                    options,
                    s1);
            if (n == JOptionPane.YES_OPTION) {
                return true;
            } else {
                return false;
         private void newFrag()
              Frag frag = new FragImpl();
        public static void main(String[] args) {
            Framework framework = new Framework();
    class MyFrame extends JFrame {
        protected Dimension defaultSize = new Dimension(200, 200);
        protected Framework framework = null;
        private Color color = Color.yellow;
        private Container c;
        JTextArea textArea;
        public MyFrame(Framework controller) {
            super("New Frame");
            framework = controller;
            setDefaultCloseOperation(DISPOSE_ON_CLOSE);
            setSize(defaultSize);
            //Create a text area.
            textArea = new JTextArea(
                    "This is an editable JTextArea " +
                    "that has been initialized with the setText method. " +
                    "A text area is a \"plain\" text component, " +
                    "which means that although it can display text " +
                    "in any font, all of the text is in the same font."
            textArea.setFont(new Font("Serif", Font.ITALIC, 16));
            textArea.setLineWrap(true);
            textArea.setWrapStyleWord(true);
            textArea.setBackground ( Color.yellow );
            JScrollPane areaScrollPane = new JScrollPane(textArea);
            //Create the status area.
            JPanel statusPane = new JPanel(new GridLayout(1, 1));
            ImageIcon icoOpen = null;
            URL url = null;
            try
                icoOpen = new ImageIcon("post_it0a.gif"); //("doc04d.gif");
            catch(Exception ex)
                ex.printStackTrace();
                System.exit(1);
            setIconImage(icoOpen.getImage());
            c = getContentPane();
            c.setBackground ( Color.yellow );
            c.add ( areaScrollPane, BorderLayout.CENTER )  ;
            c.add ( statusPane, BorderLayout.SOUTH );
            c.repaint ();
    }

    Yeah!!! It works. Turned out to be a combination of DrKlap's and Martisan's suggestions -- had to change var frame's declaration from JFrame to MyFrame:
        MyFrame frame;Next, created the external class -- but again changed JFrame references to MyFrame:
    public class ShowOnExit extends WindowAdapter {
    //   JFrame aFrame;
       MyFrame aFrame;
       public ShowOnExit(MyFrame f) {
          aFrame = f;
       public void windowClosing(WindowEvent e)
          System.out.println("Why me???" + aFrame.textArea.getText()); // aFrame here not frame !!!
    }This worked. So looks like even though the original code added a WindowListener to 'frame', the listener didn't couldn't access frame's methods unless it was explicitly passed in as a parameter. Let me know if that's wrong.
    Thanks again, all.

  • Using of javax.swing.text package

    Where can I find any resources devoted to using javax.swing.text package?

    At the end of the API documentation for that package you may notice this:
    <quote>
    Related Documentation
    For overviews, tutorials, examples, guides, and tool documentation, please see:
    Using Text Components, a section in The Java Tutorial.
    </quote>

  • Error "javax.swing.JFrame"  cannot find symbol  frame.getContentPane90.add

    Getting above errror when running the code below.how do I install the Jframe so the program can see it.Looks like JRE and JDK does not have it.
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    public class SimpleGui1{
    public static void main(String []args){
    JFrame frame = new JFrame();
    JButton button = new JButton("click me");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.getContentPane90.add(button);
    frame.setSize(300,300);
    frame.setVisible(true);
    }

    This is the single most amazing thread I have ever+* seen.                                                                                                                                                                                                   

  • Can't use import javax.swing.RowFilter; in javafx

    Dear all,
    I'm a question for you.
    I developed a javafx application in which I use also swing dialog and swingx libraries.
    The question is I can't use jtable filter of java jdf 1.6
    That is when I try to add in my netbeans javafx project
    import javax.swing.RowFilter;
    it says me it's not correct library
    If I create a java swing application I can add this include.
    Why it?
    I edited netbeans conf to set javafx sdk to javafx lib I downloaded (whole sdk), not that one with netbeans, but nothing.
    It seems like I can't use this import in javafx application.
    Is it posbbile?
    Please help me

    The reason you cannot use it is because javax.swing.RowFilter was introduced in Java 1.6 . Netbeans compiles JavaFX to work with Java 1.5, which does not have the class in question.
    I have gotten around this by going to the properties->Libraries->Add JAR/Folder menu and included the jre/lib/rt.jar file from the jre directly into my project.
    Someone else posted a similar solution and more detailed explanation here: http://steveonjava.com/hacking-javafx-10-to-use-java-16-features/

  • Java.lang.ClassNotFoundException: javax.swing.JFrame

    i have developed a program in java and it is working fine in windows xp, but when i try to execute it in redhat linux, the ff errors are generated:
    Exception in thread "main" java.lang.InternalError: Unexpected exception while defining class WESMOMP$1: java.lang.ClassNotFoundException: javax.net.ssl.HostnameVerifier
       at 0x00362ca3: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00355b1e: java.lang.Error.Error(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00363086: java.lang.VirtualMachineError.VirtualMachineError(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003574be: java.lang.InternalError.InternalError(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00354abf: java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int, java.security.ProtectionDomain) (/usr/lib/./libgcj.so.3)
       at 0x003548a3: java.lang.ClassLoader.defineClass(java.lang.String, byte[], int, int) (/usr/lib/./libgcj.so.3)
       at 0x003ebd96: java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003420f7: gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00354794: java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/./libgcj.so.3)
       at 0x003427fc: _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/./libgcj.so.3)
       at 0x0033ec6d: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/./libgcj.so.3)
       at 0x0033549f: _Jv_BytecodeVerifier.verify_instructions_0() (/usr/lib/./libgcj.so.3)
       at 0x0032b7c7: _Jv_VerifyMethod(_Jv_InterpMethod) (/usr/lib/./libgcj.so.3)
       at 0x00323a64: _Jv_PrepareClass(java.lang.Class) (/usr/lib/./libgcj.so.3)
       at 0x00341f88: java.lang.ClassLoader.linkClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
       at 0x00354b43: java.lang.ClassLoader.resolveClass0(java.lang.Class) (/usr/lib/./libgcj.so.3)
       at 0x003403fc: java.lang.Class.initializeClass() (/usr/lib/./libgcj.so.3)
       at 0x0033ec94: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/./libgcj.so.3)
       at 0x0033ed2f: java.lang.Class.forName(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003a6e81: gnu.gcj.runtime.FirstThread.run() (/usr/lib/./libgcj.so.3)
       at 0x00349aec: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/./libgcj.so.3)
       at 0x0031682c: _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/./libgcj.so.3)
       at 0x08048930: ?? (??:0)
       at 0x006f778a: __libc_start_main (/lib/tls/libc.so.6)
       at 0x080486e1: ?? (??:0)I think that java cannot see the javax package.
    also i tried to execute a java program that uses mysql connector, it generated this error:
    java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
       at 0x00362ca3: java.lang.Throwable.Throwable(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00355b62: java.lang.Exception.Exception(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x00355218: java.lang.ClassNotFoundException.ClassNotFoundException(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003ebdb9: java.net.URLClassLoader.findClass(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003420f7: gnu.gcj.runtime.VMClassLoader.findClass(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x003547af: java.lang.ClassLoader.loadClass(java.lang.String, boolean) (/usr/lib/./libgcj.so.3)
       at 0x00342839: _Jv_FindClass(_Jv_Utf8Const, java.lang.ClassLoader) (/usr/lib/./libgcj.so.3)
       at 0x0033ec6d: java.lang.Class.forName(java.lang.String, boolean, java.lang.ClassLoader) (/usr/lib/./libgcj.so.3)
       at 0x0033ed2f: java.lang.Class.forName(java.lang.String) (/usr/lib/./libgcj.so.3)
       at 0x0047d007: ffi_call_SYSV (/usr/lib/./libgcj.so.3)
       at 0x0047cfc7: ffi_raw_call (/usr/lib/./libgcj.so.3)
       at 0x0032a658: _Jv_InterpMethod.continue1(_Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
       at 0x0032af64: _Jv_InterpMethod.run(ffi_cif, void, ffi_raw, _Jv_InterpMethodInvocation) (/usr/lib/./libgcj.so.3)
       at 0x00328474: _Jv_InterpMethod.run_normal(ffi_cif, void, ffi_raw, void) (/usr/lib/./libgcj.so.3)
       at 0x0047ce7c: ?? (??:0)
       at 0x0033cd68: gnu.gcj.runtime.FirstThread.call_main() (/usr/lib/./libgcj.so.3)
       at 0x003a6e91: gnu.gcj.runtime.FirstThread.run() (/usr/lib/./libgcj.so.3)
       at 0x00349aec: _Jv_ThreadRun(java.lang.Thread) (/usr/lib/./libgcj.so.3)
       at 0x0031682c: _Jv_RunMain(java.lang.Class, byte const, int, byte const, boolean) (/usr/lib/./libgcj.so.3)
       at 0x08048930: ?? (??:0)
       at 0x0074c78a: __libc_start_main (/lib/tls/libc.so.6)
       at 0x080486e1: ?? (??:0)how to install the mysql jdbc connector?
    please help...thx

    First: Check java version
    $java -version
    Second: Run your program with explicit classpath declaration
    $java -cp yourjdbcdriver.jar;yourprogram.jar com.you.program.ClassContainingMainMethodI'm not sure what to use for jar's delimeter semicolon, or colon. Try both.

  • Javax.swing.JFrame snapping ?

    Hi,
    I'll get right to the point.
    I would like to make my jFrames "snap" together when they're close to each other and keep snapped together when they do this. A lot like WinAMP does with it's windows. I have tried to write this snapping code by myself using ComponentMoved(ComponentEvent e) but I humble in the dark when it comes to snapping ... and also the code I wrote just snaps (in a bit buggy way) to the edge of the screen, not to other jFrames. I have looked around and found that java Look and Feel (www.lf2prod.com) has something called windowsnapping ... but the documentation is empty, and I'm more then ever confused. Is there a way to do this "snapping"? Are there methods already written that could simplify my task ? If not, any suggestions on how to implement this window snapping feature by scratch ?
    Thank you all,
    s0gno

    I'm looking for the same thing... except for JInternalFrames. I haven't been able to find anything even remotely close to addressing this issue.

  • Help ! inaccurate time recorded using javax.swing.timer

    Hi All,
    I am currently trying to write a stopwatch for timing application events such as loggon, save, exit ... for this I have created a simple Swing GUI and I am using the javax.swing.timer and updating a the time on a Jlabel. The trouble that I am having is that the time is out by up to 20 seconds over a 10 mins. Is there any way to get a more accruate time ?? The code that I am using is attached below.
    private Timer run = new Timer(1000, new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
    timeTaken.setText("<html><font size = 5><b>" + (df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds++)) + "</b></font><html>");
    receordedTimeValue = ((df.format(timeHours)) + ":" + (df.format(timeMins)) + ":"
    + (df.format(timeSeconds)));
    if (timeSeconds == 60) {
    timeMins++;
    timeSeconds = 0;
    if (timeMins == 60) {
    timeHours++;
    timeMins = 0;

    To get more accurate time you should use the System.currentTimeMillis() method.
    Try this code :
    import java.util.*;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class CountUpLabel extends JLabel{
         javax.swing.Timer timer;
         long startTime, count;
         public CountUpLabel() {
              super(" ", SwingConstants.CENTER);
              timer = new javax.swing.Timer(500, new ActionListener() { // less than or equal to 1000 (1000, 500, 250,200,100) 
                   public void actionPerformed(ActionEvent event) {
                        if (startTime == -1) {          
                             count = 0;               
                             startTime = System.currentTimeMillis();
                        else {
                             count = System.currentTimeMillis()-startTime;
                        setText(getStringTime(count));
         private static final String getStringTime(long millis) {
              int seconds = (int)(millis/1000);
              int minutes = (int)(seconds/60);
              int hours = (int)(minutes/60);
              minutes -= hours*60;
              seconds -= (hours*3600)+(minutes*60);
              return(((hours<10)?"0"+hours:""+hours)+":"+((minutes<10)?"0"+minutes:""+minutes)+":"+((seconds<10)?"0"+seconds:""+seconds));
         public void start() {
              startTime = -1;
              timer.setInitialDelay(0);
              timer.start();
         public long stop() {
              timer.stop();
              return(count);
         public static void main(String[] args) {
              JFrame frame = new JFrame("Countdown");
              CountUpLabel countUp = new CountUpLabel();
              frame.getContentPane().add(countUp, BorderLayout.CENTER);
              frame.setBounds(200,200,200,100);
              frame.setVisible(true);
              countUp.start();
    Denis

  • Swings-JFrame

    IN my program ,JFrame,JButton1 named VIEW ALL ,JComboBox ,JButton2 by clicking this calender will be displayed select the date ,that selected date will come into JComboBox,JButton3 named BY DATE.
    when click on VIEW ALL button data from the database(oracle 10g) will be retrieved into JTable, that table will be displayed in same JFrame.
    If we click on BY DATE button data will be displayed by that date only in the same JFrame.
    view is like this:
    VIEW ALL JCOmboBox JButton2 BY DATE
    display of JTable resultsin the same frame
    i have written the code for JTable like this;
    package crm;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import javax.swing.table.*;
    import java.sql.*;
    import java.util.*;
    import java.lang.*;
    * @author rajeshwari
    public class Callbacks extends javax.swing.JFrame {
    JTable table;
         JTableHeader header;
         Vector data = new Vector();
         String colnames[];
    public Callbacks() {
    getConnection();
    /** 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() {
    // jPanel1 = new javax.swing.JPanel();
    // jPanel2 = new javax.swing.JPanel();
    // jButton1 = new javax.swing.JButton();
    // jButton2 = new javax.swing.JButton();
    // jButton3 = new javax.swing.JButton();
    // jButton4 = new javax.swing.JButton();
    // jButton5 = new javax.swing.JButton();
    // jButton6 = new javax.swing.JButton();
    // jButton7 = new javax.swing.JButton();
    // jLabel1 = new javax.swing.JLabel();
    // jTextField1 = new javax.swing.JTextField();
    // jLabel2 = new javax.swing.JLabel();
    // jTextField2 = new javax.swing.JTextField();
    // jLabel3 = new javax.swing.JLabel();
    // jScrollPane1 = new javax.swing.JScrollPane();
    // jTextArea1 = new javax.swing.JTextArea();
    // jLabel4 = new javax.swing.JLabel();
    // jTextField3 = new javax.swing.JTextField();
    // jLabel5 = new javax.swing.JLabel();
    // jTextField4 = new javax.swing.JTextField();
    // jLabel6 = new javax.swing.JLabel();
    // jTextField5 = new javax.swing.JTextField();
    // jLabel7 = new javax.swing.JLabel();
    // jTextField6 = new javax.swing.JTextField();
    // jLabel8 = new javax.swing.JLabel();
    // jTextField7 = new javax.swing.JTextField();
    // jLabel9 = new javax.swing.JLabel();
    // jTextField8 = new javax.swing.JTextField();
    // jLabel10 = new javax.swing.JLabel();
    // jTextField9 = new javax.swing.JTextField();
    // jLabel11 = new javax.swing.JLabel();
    // jTextField10 = new javax.swing.JTextField();
    // jButton8 = new javax.swing.JButton();
    // jButton9 = new javax.swing.JButton();
    // jPanel3 = new javax.swing.JPanel();
    // jLabel12 = new javax.swing.JLabel();
    // jTextField11 = new javax.swing.JTextField();
    // jLabel13 = new javax.swing.JLabel();
    // jTextField12 = new javax.swing.JTextField();
    // jLabel14 = new javax.swing.JLabel();
    // jTextField13 = new javax.swing.JTextField();
    // jLabel15 = new javax.swing.JLabel();
    // jTextField14 = new javax.swing.JTextField();
    // jScrollPane2 = new javax.swing.JScrollPane();
    // jTextPane1 = new javax.swing.JTextPane();
    // jButton10 = new javax.swing.JButton();
    // jScrollPane3 = new javax.swing.JScrollPane();
    // jTextPane2 = new javax.swing.JTextPane();
    // jMenuBar1 = new javax.swing.JMenuBar();
    // jMenu1 = new javax.swing.JMenu();
    // jMenu2 = new javax.swing.JMenu();
    // jMenu3 = new javax.swing.JMenu();
    // jMenu4 = new javax.swing.JMenu();
    // jMenu5 = new javax.swing.JMenu();
    // jMenu6 = new javax.swing.JMenu();
    // jMenu7 = new javax.swing.JMenu();
    // jMenu8 = new javax.swing.JMenu();
    // setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    // jButton1.setText("Call Back");
    // jButton2.setText("Not Interested");
    // jButton3.setText("Person Not Available\n");
    // jButton4.setText("Answering Machine");
    // jButton5.setText("Person Available");
    // jButton6.setText("Do not Call");
    // jButton7.setText("Next>>...");
    // org.jdesktop.layout.GroupLayout jPanel2Layout = new org.jdesktop.layout.GroupLayout(jPanel2);
    // jPanel2.setLayout(jPanel2Layout);
    // jPanel2Layout.setHorizontalGroup(
    // jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel2Layout.createSequentialGroup()
    // .addContainerGap()
    // .add(jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jButton2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
    // .add(jButton7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)))
    // jPanel2Layout.setVerticalGroup(
    // jPanel2Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel2Layout.createSequentialGroup()
    // .addContainerGap()
    // .add(jButton1)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton2)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton3)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton4)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton5)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton6)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jButton7)
    // .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    // jLabel1.setText("\nCustomer ID:");
    // jTextField1.setText("852");
    // jLabel2.setText("Customer Name:");
    // jTextField2.setText("Rajeshwari");
    // jLabel3.setText("Address:");
    // jTextArea1.setColumns(20);
    // jTextArea1.setRows(5);
    // jScrollPane1.setViewportView(jTextArea1);
    // jLabel4.setText("City:");
    // jTextField3.setText("HYD");
    // jLabel5.setText("State:");
    // jTextField4.setText("A.P");
    // jLabel6.setText("Zip:");
    // jTextField5.setText("39");
    // jLabel7.setText("Phone:");
    // jTextField6.setText("220288");
    // jLabel8.setText("Mobile:");
    // jTextField7.setText("9949162978");
    // jLabel9.setText("Fax:");
    // jTextField8.setText("2343535");
    // jLabel10.setText("Email:");
    // jTextField9.setText("[email protected]");
    // jLabel11.setText("Call Time:");
    // jTextField10.setText("12:34:23");
    // jButton8.setText("Call Backs");
    // jButton8.addActionListener(new java.awt.event.ActionListener() {
    // public void actionPerformed(java.awt.event.ActionEvent evt) {
    // jButton8ActionPerformed(evt);
    // jButton9.setText("Hang");
    // jLabel12.setText("Call Back Date:");
    // jTextField11.setText("12-03-98");
    // jLabel13.setText("Call Back Time:");
    // jTextField12.setText("12:23:45");
    // jLabel14.setText("Called on:");
    // jTextField13.setText("11:12:99");
    // jLabel15.setText("Called At:");
    // jTextField14.setText("jTextField14");
    // jScrollPane2.setViewportView(jTextPane1);
    // jButton10.setText("ADD");
    // org.jdesktop.layout.GroupLayout jPanel3Layout = new org.jdesktop.layout.GroupLayout(jPanel3);
    // jPanel3.setLayout(jPanel3Layout);
    // jPanel3Layout.setHorizontalGroup(
    // jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel3Layout.createSequentialGroup()
    // .addContainerGap()
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jLabel12)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jTextField11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jLabel13)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jTextField12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))
    // .add(27, 27, 27)
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jLabel14)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jTextField13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 84, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jLabel15)
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jTextField14))))
    // .add(jPanel3Layout.createSequentialGroup()
    // .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 187, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(28, 28, 28)
    // .add(jButton10)))
    // .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    // jPanel3Layout.setVerticalGroup(
    // jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel3Layout.createSequentialGroup()
    // .addContainerGap()
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel12)
    // .add(jTextField11, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jLabel14)
    // .add(jTextField13, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(17, 17, 17)
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel13)
    // .add(jTextField12, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jLabel15)
    // .add(jTextField14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jPanel3Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jScrollPane2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 69, Short.MAX_VALUE)
    // .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel3Layout.createSequentialGroup()
    // .add(jButton10)
    // .add(22, 22, 22))))
    // jScrollPane3.setViewportView(jTextPane2);
    // org.jdesktop.layout.GroupLayout jPanel1Layout = new org.jdesktop.layout.GroupLayout(jPanel1);
    // jPanel1.setLayout(jPanel1Layout);
    // jPanel1Layout.setHorizontalGroup(
    // jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(org.jdesktop.layout.GroupLayout.TRAILING, jPanel1Layout.createSequentialGroup()
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(30, 30, 30)
    // .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(32, 32, 32)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jLabel2)
    // .add(jLabel1)
    // .add(jLabel3)
    // .add(jLabel4)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
    // .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    // .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 46, Short.MAX_VALUE)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jTextField1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
    // .add(jTextField2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 157, Short.MAX_VALUE)
    // .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 149, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(58, 58, 58))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    // .add(org.jdesktop.layout.GroupLayout.LEADING, jTextField3, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
    // .add(jTextField4, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE))
    // .add(66, 66, 66))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jTextField5, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 149, Short.MAX_VALUE)
    // .add(66, 66, 66))))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(254, 254, 254)))
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jButton8)
    // .add(27, 27, 27)
    // .add(jButton9))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
    // .add(jLabel7, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    // .add(jLabel8, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    // .add(org.jdesktop.layout.GroupLayout.LEADING, jLabel9))
    // .add(jLabel10)
    // .add(jLabel11))
    // .add(6, 6, 6)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
    // .add(jTextField10)
    // .add(jTextField9)
    // .add(jTextField8)
    // .add(jTextField7)
    // .add(jTextField6, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 148, Short.MAX_VALUE)))
    // .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 212, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(45, 45, 45))
    // jPanel1Layout.setVerticalGroup(
    // jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(23, 23, 23)
    // .add(jPanel2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(42, 42, 42)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel1)
    // .add(jTextField1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jLabel7)
    // .add(jTextField6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(16, 16, 16)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel2)
    // .add(jTextField2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(25, 25, 25)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(jScrollPane1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jLabel3))
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED, 17, Short.MAX_VALUE)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel4)
    // .add(jTextField3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(18, 18, 18)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel5)
    // .add(jTextField4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jTextField5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jButton8)
    // .add(jButton9)
    // .add(jLabel6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 34, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED))
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(27, 27, 27)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel8)
    // .add(jTextField7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(27, 27, 27)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel9)
    // .add(jTextField8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(27, 27, 27)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel10)
    // .add(jTextField9, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
    // .add(34, 34, 34)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
    // .add(jLabel11)
    // .add(jTextField10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))))
    // .add(63, 63, 63)
    // .add(jPanel1Layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
    // .add(jPanel3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(jPanel1Layout.createSequentialGroup()
    // .add(jScrollPane3, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 88, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .add(44, 44, 44))))
    // jMenu1.setText("start");
    // jMenuBar1.add(jMenu1);
    // jMenu2.setText("Leads");
    // jMenuBar1.add(jMenu2);
    // jMenu3.setText("Campaign");
    // jMenuBar1.add(jMenu3);
    // jMenu4.setText("Reports");
    // jMenuBar1.add(jMenu4);
    // jMenu5.setText("Recordings");
    // jMenuBar1.add(jMenu5);
    // jMenu6.setText("Agents");
    // jMenuBar1.add(jMenu6);
    // jMenu7.setText("Time Zones");
    // jMenuBar1.add(jMenu7);
    // jMenu8.setText("Help");
    // jMenuBar1.add(jMenu8);
    // setJMenuBar(jMenuBar1);
    // org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
    // getContentPane().setLayout(layout);
    // layout.setHorizontalGroup(
    // layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(layout.createSequentialGroup()
    // .add(jPanel1, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
    // .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    // layout.setVerticalGroup(
    // layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
    // .add(layout.createSequentialGroup()
    // .add(78, 78, 78)
    // .add(jPanel1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    // pack();
    // }// </editor-fold>
    public void getConnection()
    // Object src=evt.getSource();
    String name="";
    String call_back_date="";
    String call_back_time="";
    String called_on="";
    String called_at="";
    String phone="";
    String comments="";
    // if(src==jButton8)
    try{
    colnames=new String[]{"name","call_back_date","call_back_time","called_on","called_at","phone","comments"};
    Class.forName("oracle.jdbc.driver.OracleDriver");
    String url="jdbc:oracle:thin:@localhost:1521:oracle";
    Connection con=DriverManager.getConnection(url,"scott","root");
    Statement st=con.createStatement();
    ResultSet rs=st.executeQuery("select * from Callbacks_details");
              while (rs.next())
              name=rs.getString("name");
              call_back_date=rs.getString("call_back_date");
              call_back_time=rs.getString("call_back_time");
    called_on=rs.getString("called_on");
    called_at=rs.getString("called_at");
              phone=rs.getString("phone");
    comments=rs.getString("comments");
    Vector row = new Vector(colnames.length);
    // Vector r=new Vector();
              row.addElement(name);
              row.addElement(call_back_date);
              row.addElement(call_back_time);
    row.addElement(called_on);
    row.addElement(called_at);
              row.addElement(phone);
    row.addElement(comments);
              data.addElement(row);
    // System.out.println(data);
    catch(Exception a)
    a.printStackTrace();
    System.out.println(a);
    table=new JTable(new MyTableModel(colnames,data));
    //int n=table.getColumnCount();
              TableColumn column=null;
              for (int i = 0; i<colnames.length; i++) {
              column = table.getColumnModel().getColumn(i);
         column.setPreferredWidth(100);
              JScrollPane scrollPane = new JScrollPane(table);
              getContentPane().add(scrollPane);
    public class MyTableModel extends AbstractTableModel{
    String[] columnNames;
         Vector d= new Vector(6);
    MyTableModel(String[] columnNames, Vector data){
         this.columnNames = columnNames;
         d = data;
    public int getColumnCount() {
    return columnNames.length;
    public int getRowCount() {
    return d.size();
    public String getColumnName(int col) {
    return columnNames[col];
    public Object getValueAt(int row, int col) {
         Vector d

    for displaying table on same frame(do not cross post and use code tags just click CODE and paste the code in between)
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.event.ActionEvent;
    import java.awt.event.ActionListener;
    import javax.swing.JFrame;
    public class TableShow extends JFrame{
        /** Creates a new instance of TableShow */
        private javax.swing.JButton jButton1;
        private javax.swing.JPanel jPanel1;
        private javax.swing.JScrollPane jScrollPane1;
        private javax.swing.JTable jTable1;
        public TableShow() {
            jTable1 = new javax.swing.JTable(5,5);
            jScrollPane1 = new javax.swing.JScrollPane(jTable1);
            jButton1 = new javax.swing.JButton("Show");
            jPanel1 = new javax.swing.JPanel();
            jPanel1.setLayout(new BorderLayout());
            jPanel1.add(jScrollPane1);
            jScrollPane1.setVisible(false);
            getContentPane().add(jButton1, BorderLayout.NORTH);
            getContentPane().add(jPanel1, BorderLayout.CENTER);
            setVisible(true);
            setSize(300,300);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            jButton1.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    if(jScrollPane1.isVisible()) {
                        jScrollPane1.setVisible(false);
                    } else{
                        jScrollPane1.setVisible(true);
                    jPanel1.validate();
        public static void main(String args[]){
            new TableShow();
    }

  • GUI Problem (Swing JFrame/JPanel). HELP!

    Hi,
    I made an small application for calculate some things.
    I download i piece of code for creating bar chart and i icluded in my code. But i have problem when i am trying to show the chart in the Frame. All the buttons, textfields, labels goes to left and half are hiding.
    If i open the chart on a new frame i dont have problem.
    the problem apears when after i put the panel in the frame i try to put the chart in the frame. Look the code:
    add(p);     //Put the panel in the Frame
    this.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant")); // <-- The problem!!that command mades me the problem!
    Here are 2 screenshots
    1. When i put the chart in the Frame (the problem)
    http://www.iweb.gr/images/InFrame.jpg
    2. When i put the chart on new frame (works fine)
    http://www.iweb.gr/images/NewFrame.jpg
    Hopes someone can help. Thanks
    The code List:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    //The main class of the program
    public class PlantFertilizer  extends JFrame{//The main class is a subclass of Frame
         private Label lN, lP,lK;//These show the value of the observable
         public TextField tN, tP, tK;
         private MyData thedata;//The observable we are going to watch
         private double[] values=new double[3];
        private String[] names=new String[3];
        private String title;
    public PlantFertilizer(){
         thedata=new MyData();// create the observable
         addWindowListener(new WindowAdapter(){//if user closes the Frame, quit
              public void windowClosing(WindowEvent e){
                   System.exit(0);
         setSize(400,500);//Set size
         setTitle(getClass().getName()+" By Pantelis Stoumpis");
         JPanel p = new JPanel();    //Make a panel for buttons and output
         //Input Data Area
         p.add(new Label("-------------------------Input Data Area--------------------------",Label.CENTER));
         p.add(new Label("Nitrogen (N)"));
         tN = new TextField();p.add(tN);
         p.add(new Label("Phosphorus (P)"));
         tP = new TextField();p.add(tP);
         p.add(new Label("Potassium (K)"));
         tK = new TextField();p.add(tK);
         lN=new Label("N = %", Label.CENTER);
         p.add(lN);     //Put the N label in the panel
         lP=new Label("P = %", Label.CENTER);
         p.add(lP);          //Put the P label in the panel
         lK=new Label("K = %", Label.CENTER);
         p.add(lK);          //Put the K label in the panel
         addButton(p,"Apply",          //Apply new Values
         new ActionListener(){
         public void actionPerformed(ActionEvent evt){
              int iNt = Integer.parseInt(tN.getText());
              int iPt = Integer.parseInt(tP.getText());
              int iKt = Integer.parseInt(tK.getText());
              thedata.addOne(iNt,iPt,iKt);          //which adds one to the observable
              JFrame f = new JFrame();
             f.setSize(400, 300);
              values[0] = 40;
             names[0] = "N";
             values[1] = 20;
             names[1] = "P";
             values[2] = 30;
             names[2] = "K";
             f.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant"));
              f.setVisible(true);
         addButton(p,"Close",          //add a close button to quit the program
         new ActionListener(){
         public void actionPerformed(ActionEvent evt){
              System.exit(0);
    add(p);     //Put the panel in the Frame
    this.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant")); // <-- The problem!!
    //A utility function to add a button with a given title and action
    public void addButton(Container c, String title,ActionListener a)
              Button b=new Button(title);
              c.add(b);
              b.addActionListener(a);
    public class ChartPanel extends JPanel {
      private double[] values;
      private String[] names;
      private String title;
      public ChartPanel(double[] v, String[] n, String t) {
        names = n;
        values = v;
        title = t;
      public void paintComponent(Graphics g) {
        super.paintComponent(g);
        if (values == null || values.length == 0)
          return;
        double minValue = 0;
        double maxValue = 0;
        for (int i = 0; i < values.length; i++) {
          if (minValue > values)
    minValue = values[i];
    if (maxValue < values[i])
    maxValue = values[i];
    //Dimension d = getSize();
    //int clientWidth = d.width;
    //int clientHeight = d.height;
    //int barWidth = clientWidth / values.length;
    //Dimension d = 100;
         int clientWidth = 100;
         int clientHeight = 150;
    int barWidth = clientWidth / values.length;
    Font titleFont = new Font("SansSerif", Font.BOLD, 12);
    FontMetrics titleFontMetrics = g.getFontMetrics(titleFont);
    Font labelFont = new Font("SansSerif", Font.PLAIN, 10);
    FontMetrics labelFontMetrics = g.getFontMetrics(labelFont);
    int titleWidth = titleFontMetrics.stringWidth(title);
    int y = titleFontMetrics.getAscent();
    int x = (clientWidth - titleWidth) / 2;
    g.setFont(titleFont);
    g.drawString(title, 10, 300);
    int top = titleFontMetrics.getHeight();
    int bottom = labelFontMetrics.getHeight();
    if (maxValue == minValue)
    return;
    double scale = (clientHeight - top - bottom) / (maxValue - minValue);
    y = clientHeight - labelFontMetrics.getDescent();
    g.setFont(labelFont);
    for (int i = 0; i < values.length; i++) {
    int valueX = i * barWidth + 1;
    int valueY = top;
    int height = (int) (values[i] * scale);
    if (values[i] >= 0)
    valueY += (int) ((maxValue - values[i]) * scale);
    else {
    valueY += (int) (maxValue * scale);
    height = -height;
    g.setColor(Color.red);
    g.fillRect(valueX, valueY, barWidth - 2, height);
    g.setColor(Color.black);
    g.drawRect(valueX, valueY, barWidth - 2, height);
    int labelWidth = labelFontMetrics.stringWidth(names[i]);
    x = i * barWidth + (barWidth - labelWidth) / 2;
    g.drawString(names[i], x, y);
    //main is called when we start the application
    public static void main(String[]args){
                   PlantFertilizer od = new PlantFertilizer();//make an observationsDemo frame
                   NWatcher watchitN = new NWatcher(od.lN);//make an observer
                   od.thedata.addObserver(watchitN);//register observer with the observable
                   PWatcher watchitP = new PWatcher(od.lP);//make an observer
                   od.thedata.addObserver(watchitP);//register observer with the observable
                   KWatcher watchitK = new KWatcher(od.lK);//make an observer
                   od.thedata.addObserver(watchitK);//register observer with the observable
                   od.setVisible(true);//show the frame on the screen

    Why are you putting Labels and TextFields (heavyweight AWT components) into a lightweight JPanels?
    What's the first rule of Swing? DO NOT MIX heavyweight AWT components and lightweight Swing components. Period. Never.
    There's Swing equivalents for every single AWT component, and then some. There's no excuse for not using them.
    However, if this chart library code is AWT based, then you should make a completely AWT based UI. Or find a different library based on Swing (like JFreeChart).
    And finally:
    add(p);     //Put the panel in the Frame
    this.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant")); // <-- The problem!!is wrong....
    add(p);      // <-- The problem!!
    this.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant"));You don't call add on JFrame or JDialog to add things to it, unless you know what you're doing. And you clearly don't, else you wouldn't have done it. What you probably want to do is this:
    this.getContentPane().add(p, BorderLayout.SOUTH);
    this.getContentPane().add(new ChartPanel(values, names, "Fertilizer Plant"), BorderLayout.CENTER);

  • Javax.swing.KeyStroke

    When i use Swing with PJ i get some errors about javax.swing.KeyStroke:
    java.lang.NoSuchFieldException
    at java.lang.Class.getField()
    at javax.swing.KeyStroke.getKeyStroke()
    at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults()
    at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults()
    at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults()
    at javax.swing.UIManager.setLookAndFeel()
    at javax.swing.UIManager.setLookAndFeel()
    at javax.swing.UIManager.initializeDefaultLAF()
    at javax.swing.UIManager.initialize()
    at javax.swing.UIManager.maybeInitialize()
    at javax.swing.UIManager.getUI()
    at javax.swing.JPanel.updateUI()
    at javax.swing.JPanel.<init>()
    at javax.swing.JPanel.<init>()
    at javax.swing.JRootPane.createGlassPane()
    at javax.swing.JRootPane.<init>()
    at javax.swing.JFrame.createRootPane()
    at javax.swing.JFrame.frameInit()
    at javax.swing.JFrame.<init>()
    java.lang.Error: Unrecognized keycode name: VK_KP_LEFT
    at javax.swing.KeyStroke.getKeyStroke()
    at javax.swing.plaf.metal.MetalLookAndFeel.initComponentDefaults()
    at javax.swing.plaf.basic.BasicLookAndFeel.getDefaults()
    at javax.swing.plaf.metal.MetalLookAndFeel.getDefaults()
    at javax.swing.UIManager.setLookAndFeel()
    at javax.swing.UIManager.setLookAndFeel()
    at javax.swing.UIManager.initializeDefaultLAF()
    at javax.swing.UIManager.initialize()
    at javax.swing.UIManager.maybeInitialize()
    at javax.swing.UIManager.getUI()
    at javax.swing.JPanel.updateUI()
    at javax.swing.JPanel.<init>()
    at javax.swing.JPanel.<init>()
    at javax.swing.JRootPane.createGlassPane()
    at javax.swing.JRootPane.<init>()
    at javax.swing.JFrame.createRootPane()
    at javax.swing.JFrame.frameInit()
    at javax.swing.JFrame.<init>()
    Could someone help me?

    Refer to the bug database (bugid = 4309057)
    http://developer.java.sun.com/developer/bugParade/bugs/4309057.html
    Here the workaround:
    Fix the problem yourself by changing SwingUtilites to test for "Class.getPackage" which is 1.2 specific and has not been introduced to pJava:
    Method m = Class.class.getMethod("getPackage", null);Re-Jar the swingclasses and enjoy your Swing application running on PersonalJava....
    Herbie

  • Where did javax.swing.plaf.metal go after 1.4?

    Dear Users of the java.swing libraries,
    I've made a schoolproject in javax.swing and i am using the javax.swing.plaf.metal.MetalLookAndFeel as LookAndFeel.
    The Problem is: it seems sun has removed the Metal LookAndFeel in versions past 1.4 or something like that. I read this in the source DefaultmetalTheme.java file:
    * This class describes the default Metal Theme.
    * <p>
    * <strong>Warning:</strong>
    * Serialized objects of this class will not be compatible with
    * future Swing releases. The current serialization support is
    * appropriate for short term storage or RMI between applications running
    * the same version of Swing.  As of 1.4, support for long term storage
    * of all JavaBeans<sup><font size="-2">TM</font></sup>
    * has been added to the <code>java.beans</code> package.
    * Please see {@link java.beans.XMLEncoder}.
    * @version 1.25 01/23/03
    * @author Steve Wilson
    */Now i wonder, can i find this cool Metal style anywhere else? In like the java.beans that was mentioned in the code of DefaultmetalTheme.java.
    In my current situation my project is ruined and i would relly appriciate some feedback on this!
    Yours Truthfully,
    Alexander Thore

    They would only be where you put them.
    You should be importing them to your computer regularly as you would with any digital camera, most especially before any update.
    If you failed to do this, then they are likely gone.
    You can try a restore from backup.

  • How to create a calculator by using javax swing

    I try to us Javax swing make some buttons like 0 - 9 then input some numbers by using those number like a calculator. But I only can get numbers no more than 9.
    Please help me.

    How do you store the number the user enters? If it's in a string and the previous value was eg "1" and the user enters "2" you get "12" with a simple concatenation: val += input.
    OTOH, if you work with doubles and the previous value was 1.0 and the user enters 2.0 by pressing the button you get 12.0 by multiplying 1.0 with 10 and adding 2.0: val = 10*val + input.

  • Using images files without javax.swing

    I am developing an applet the user can designate a background image instead of a color. This applet must not use the javax package. What class would you all recommend for creating the background image. I can't use IconImage because it is part of the javax package.
    Thanks

    checkout the Graphics class too. It has a drawImage function that paints the image class on awt components. However you must override the the paint(Graphics g) method of the component in order to display your image.

  • Newbie compiler help using javax.swing class

    current java ver java version "1.5.0_02"
    error msg
    [error]
    C:\Documents and Settings\Neil\Desktop\Java>javac neiltest2.java
    neiltest2.java:12: package javax does not exist
    import javax.swing;
    ^
    neiltest2.java:28: cannot resolve symbol
    symbol : variable JOptionPane
    location: class neiltest2
    JOptionPane.showMessageDialog(null, "The total is " + intSum);
    ^
    2 errors
    [error]
    * neiltest2.java
    * Created on 02 June 2005, 19:02
    * @author  Neil
    * @version
    import javax.swing;
    public class neiltest2 {
        /** Creates new neiltest2 */
        public neiltest2() {
        * @param args the command line arguments
        public static void main (String args[]) {
            int intSum;
            intSum = 14+35;
            JOptionPane.showMessageDialog(null, "The total is " + intSum);
            System.exit(0);
    }TIA
    Neil

    Use either
    import javax.swing.JOptionPanel;
    or
    import javax.swing.*;
    � {�                                                                                                                                                                               

Maybe you are looking for

  • Cannot see instrument in EXS folder

    Hi, I cannot see the Vienna strings I have recently bought in Logic 8 EXS. The install has gone fine, I have rebooted and repaired disc permissions. The VSL samples are in the following location Library/Application Support/Logic/Sampler Instruments/V

  • 3D layers: copy attributes or replace from file

    Sorry I can't figure this out, but it happens to me often: I create a 3D model in Cheetah3D, bring it into Photoshop CS5 Extended using 3D/New Layer From 3D File... I size, orient it, get the lights just right, get the camera perfect, then realize I

  • JDBC Adapter: unique constraint

    Hi, my scenario: IDoc -> XI -> JDBC. I would like to know whether the data processing on my Oracle database was successful or not. If an unique constraint fails on oracle (i have test it) the idoc has status successful although (XI: SXMB_MONI) . how

  • IPod not detected by Mac (doesn't show in Finder or iTunes)

    I've connected an iPod Touch to my Macbook running Snow Leopard via USB, but it's not showing up in Finder, iTunes or xcode. I've tried the iPod Troubleshooting Assistant, but no luck. The USB port should be working fine (tested with other devices, a

  • Isanbdel.vbs where can i get this at?

    I am searching all over and still not able to get this file.  Isanbdel.vbs Does anyone have it they can give to me? I have even tried paid support with microsoft and they do not have it Thanks