Swing JTabbedPane problem!!!!!!!!

hi guys
i create the UI by GUI builder of NetBeans IDE. i want to add two JPanels in JTabbedPane. But the everytime i drag the JPanel into JTabbedPane. NetBeans will generate the code and arrange two JPanels by GroupLayout. i dont want to have GroupLayout to mange the these two JPanels in JTabbedPane.
Also i know i to do it by coding manually. But I want to execute in NetBeans. Is there any properties i have to change in Netbeans.
thanks in advance

I'm currently running jdk1.6.0, although the problem occurred while running on jdk1.5.x as well. It should be noted that I'm running this on Linux, using the official JDK from Sun (not gcj or anything of the sort). The application is written in pure Swing, no AWT canvases etc. Thus far, all testing has been performed exclusively on Linux and in all cases the results have been the same (I've tested with at least 2 distributions: Slackware and Mandriva 2007).
As for development tools, the problem occurs both with the new Netbeans 5.5 (and possibly older versions, though I haven't checked) as well as eclipse running the MyEclipseIDE plugin which contains a port of the Netbeans Matisse GUI development framework. While it is possible the IDEs are generating poor code, I doubt that is the problem.
I'll need to set up a Windows box and try it out on that. If the problem still occurs, I'll write a minimal program to replicate the problem and post it here.
Thanks for the replies

Similar Messages

  • Insert tab in jTabbedPane problem

    Hi,
    I am trying to insert a tab into a JTabbedPane using this method:
    insertTab(String title, Icon icon, Component component, String tip, int index)
    It works fine - the tab is inserted to the right place on the GUI, but the problem is this - though the tab is inserted at the right location in the GUI, when I traverse through the JTabbbedPane, I see that the new tab is inserted at the last index!
    Can someone let me know how to fix this problem?
    Thanks

    Here is the example code:
    import javax.swing.JPanel;
    import javax.swing.JTabbedPane;
    import javax.swing.JTextArea;
    public class TabbedPaneTest {
        public static void main(String[] args) {
            JTabbedPane tp = new JTabbedPane();
            tp.add("tab0", new JPanel());
            tp.add("tab2", new JPanel());
            tp.add("tab3", new JPanel());
            tp.insertTab("tab1", null, new JTextArea(), null, 1);
            for (int i=0; i<tp.getComponentCount(); i++) {
                System.out.println("TabComponent"+i+": "+tp.getComponent(i));
    }The output of this test program is:
    TabComponent0: javax.swing.JPanel...
    TabComponent1: javax.swing.JPanel...
    TabComponent2: javax.swing.JPanel...
    TabComponent3: javax.swing.JTextArea...
    You can see that the JTextArea is not inserted at index 1 as expected.
    But I found the solution for this problem myself. If you replace tp.getComponent(i) by
    tp.getComponentAt(i) the program output is:
    TabComponent0: javax.swing.JPanel...
    TabComponent1: javax.swing.JTextArea...
    TabComponent2: javax.swing.JPanel...
    TabComponent3: javax.swing.JPanel...
    and this is what I need!!!

  • Java Swing application problem in Windows vista

    When we execute the Swing application in windows vista environment.
    The look and feel of the swing components are displayed improperly.
    Do we need to put any specific look and feel for windows vista environment or any specific hardware configuration is required to setup windows vista environment.
    Please give some inputs to solve the problem.
    We have tried with the following sample code to run in windows vista.
    * Vista.java
    * Created on December 5, 2006, 5:39 PM
    public class Vista extends javax.swing.JFrame {
    /** Creates new form Vista */
    public Vista() {
    initComponents();
    pack();
    /** 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 ">//GEN-BEGIN:initComponents
    private void initComponents() {
    jButton1 = new javax.swing.JButton();
    jToggleButton1 = new javax.swing.JToggleButton();
    jPanel1 = new javax.swing.JPanel();
    jCheckBox1 = new javax.swing.JCheckBox();
    jScrollPane1 = new javax.swing.JScrollPane();
    jTextArea1 = new javax.swing.JTextArea();
    jTextField1 = new javax.swing.JTextField();
    getContentPane().setLayout(null);
    setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
    jButton1.setText("Button 1");
    getContentPane().add(jButton1);
    jButton1.setBounds(20, 20, 170, 30);
    jToggleButton1.setText("Togle btn");
    getContentPane().add(jToggleButton1);
    jToggleButton1.setBounds(100, 80, 90, 20);
    jPanel1.setLayout(null);
    jCheckBox1.setText("jCheckBox1");
    jCheckBox1.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
    jCheckBox1.setMargin(new java.awt.Insets(0, 0, 0, 0));
    jPanel1.add(jCheckBox1);
    jCheckBox1.setBounds(10, 40, 130, 13);
    getContentPane().add(jPanel1);
    jPanel1.setBounds(10, 150, 200, 130);
    jTextArea1.setColumns(20);
    jTextArea1.setRows(5);
    jScrollPane1.setViewportView(jTextArea1);
    getContentPane().add(jScrollPane1);
    jScrollPane1.setBounds(210, 150, 164, 94);
    jTextField1.setText("jTextField1");
    getContentPane().add(jTextField1);
    jTextField1.setBounds(240, 30, 140, 30);
    pack();
    }// </editor-fold>//GEN-END:initComponents
    * @param args the command line arguments
    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new Vista().setVisible(true);
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables
    }

    When we execute the Swing application in windows
    vista environment.
    The look and feel of the swing components are
    displayed improperly.Improperly means what? You must be aware that Vista's native L&F certainly isn't supported yet.

  • JTabbedPane problem

    Hi all,
    I'am trying to do a swing xml editor.My editor have undo/redo function.I use JTabbedPane because i want the user to be able to open multiple file :
    undobutton | redobutton +('this are undo redo buttons with ActionListener ;buttons are not include in JTabbedPane obj')+
    file1.xml | file2.xml | file3.xml +("this is my JTabbedPane")+
    Let say i wrote smth. in all files above,and later file1.xml is selected :If i push undobutton it makes changes in all three files,but i want to undo content only in file1.xml

    It's looking like you're creating a CompoundUndoManager for each text pane, and then adding each CompoundUndoManager's undo and redo actions to your buttons as listeners. Thus each time you click one of the buttons, all of the undo (or redo) actions for all text panes will be notified.
    If you have multiple editors in an application, and a toolbar with an "undo" and "redo" button, you should probably add a TextAction to each button that determines the text component that is currently active (TextAction provides methods to do so), then grab that text component's UndoManager and have it undo/redo. That way you're only ever undo/redoing stuff on the currently active text component.
    If you need further help, you'll have to post an SSCCE. Note that an SSCCE is not just a code snippet of your current application.

  • ADF swing: JTabbedPane does not display column names.

    Hi all,
    I have created an ADF Panel, which allows the user to run a few simple queries against an Oracle database done using ADF view objects and ADF view links and ADF application module.
    From the data control area I drag and drop a view link containing a query into a JTabbedPane. But when I run the ADF panel, JTabbedPane does not display the column headers from the SQL as opposed to JScrollPane which does.
    Suppose you do a select * from departments(dep_id, manager, state_cd), you will see all column headers meaning dep_id, manager, state_cd, and under each column the corresponding data which was retuned by the SQL if you use JScrollPane. But if you use you use JTabbedPane then you would only see the data which was retuned by the SQL without seeing the column header names meaning dep_id, manager, state_cd.
    What do I need to do to make JTabbedPane display columns headers?
    I would appreciate your input.
    Thanks.
    Bobby A.

    Hi,
    JScrollPane should be used. You can add this into a JTabbedPane if you like. Not all Swing panel show table headers
    Frank

  • Adf/swing binding problem

    Hi all,
    Friends i need your help.
    I was a bit confused as i started developing an adf/swing application. I know that this project is not supported any more but i honestly believe that there are a lot of people still using it.
    I've already faced with a number of problems and successfully solved them but the one is really strange.
    Before describing it let me ask one preliminary question. It’s very important for me, but if it is too much …. skip the first question since the second one is the most important.
    1. I’m creating a multiframe application where I have one main window (with a desktop pane) which does not include any bindings and is used for invoking internal frames only which in their turn have been created by dragging and dropping data controls.
    Since JDeveloper only allows generating skeletons for stand-alone frames and there is lack of information concerned with adf/swing developing I’m trying to fit the automatically generated code for my purpose by myself.
    I obsessively ask some GURU to check my strategy and say whether I’m doing it right.
    First I create the BindingContext object in the main frame:
    BindContext ctx = newBindingContext();
    public MainFrame() {…………      
    try {
    JUMetaObjectManager.setErrorHandler(new JUErrorHandlerDlg());
    JUMetaObjectManager mgr = JUMetaObjectManager.getJUMom();
    mgr.setJClientDefFactory(null);
    ctx.put(DataControlFactory.APP_PARAM_ENV_INFO, new JUEnvInfoProvider());
    ctx.setLocaleContext(new DefLocaleContext(null));
    HashMap map = new HashMap(4);
    map.put(DataControlFactory.APP_PARAMS_BINDING_CONTEXT, ctx);
    mgr.loadCpx("minit.org.view.DataBindings.cpx" , map);
    DCDataControl app = (DCDataControl)ctx.get("AppModule1DataControl");
    app.setClientApp(DCDataControl.JCLIENT);
    } catch (Exception ex) {
    JUMetaObjectManager.reportException(null, ex, true);
    System.exit(1);
    Then I pass the BindingContext object into the internal frames constructors, i.e.
    private void jMenuUnitVoc_actionPerformed(ActionEvent e) {
    this.getJMenuUnitVoc().setEnabled(false);
    FormCreateUnitView1 unitVoc = new FormCreateUnitView1 (ctx);
    unitVoc.setVisible (true);
    this.deskTopPane.add (unitVoc);
    Then I setup the panel binding for a particular JinternalFrame instance through the automatically generated setBindingContext() method:
    public FormCreateUnitView1(BindingContext ctx) {
    try {
    this.setBindingContext(ctx);
    } catch (Exception ex) {
    JUMetaObjectManager.reportException(null, ex, true);
    System.exit(1);
    This predefined setBindingContext () method looks like this:
    public void setBindingContext(BindingContext bindCtx) {
    if (panelBinding.getPanel() == null) {
    panelBinding = panelBinding.setup(bindCtx, this);
    registerProjectGlobalVariables(bindCtx);
    panelBinding.refreshControl();
    try {
    jbInit();
    panelBinding.refreshControl();
    } catch (Exception ex) {
    panelBinding.reportException(ex);
    panelBinding instance variable is declared by default as
    private JUPanelBinding panelBinding = new JUPanelBinding("FormCreateUnitView1PageDef");
    when the internal frame is getting closed the panel binding is released:
    public void doDefaultCloseAction() {
    _popupTransactionDialog();
    panelBinding.releaseDataControl(); statusBar.release();
    MainFrame myFrame = (MainFrame)this.getDesktopPane().getParent().getParent().getParent().getParent();
    myFrame.getJMenuUnitVoc().setEnabled(true);
    super.doDefaultCloseAction();
    Why I’m asking about this is because I met another syntax which is known to be commonly used:
    Something like this:
    this is the code I use to (re)create the panel,
    the setBindingContext method.
    public void setBindingContext(BindingContext bindCtx)
    String detail2BCName = "myName";
    if (bindCtx.get(detail2BCName) == null)
    DCBindingContainerDef bcdef = (DCBindingContainerDef) JUMetaObjectManager.getJUMom() .findLoadedObject("mypackage." + detail2BCName);
    DCBindingContainer bc = bcdef.createBindingContainer(bindCtx);
    bc.setName(detail2BCName);
    bindCtx.put(detail2BCName, bc);
    // ... then calls to jbInit etc.
    this is the code I use to release the binding when
    the window is closed
    getPanelBinding.release();
    getPanelBinding.getBindingContext().remove(superPanelBinding.getName());
    …but this syntax is badly documented, so I’m a bit confused about which is right… my code works pretty fine (all master and detail frames are synchronized and all that…) except for one issue I’m going to describe.
    I’m waiting for your opinions….please help make it clear.
    THE MAIN PROBLEM
    2. I’ve got a master/detail internal frame. When I make any changes in it and then commit them through a navigation bar I get the following exception as I try to close it later through the standard close icon:
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
         at oracle.jbo.uicli.jui.JUSVUpdateableFocusAdapter.focusLost(JUSVUpdateableFocusAdapter.java:71)
         at java.awt.AWTEventMulticaster.focusLost(AWTEventMulticaster.java:172)
         at java.awt.Component.processFocusEvent(Component.java:5380)
         at java.awt.Component.processEvent(Component.java:5244)
         at java.awt.Container.processEvent(Container.java:1966)
         at java.awt.Component.dispatchEventImpl(Component.java:3955)
         at java.awt.Container.dispatchEventImpl(Container.java:2024)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.KeyboardFocusManager.redispatchEvent(KeyboardFocusManager.java:1810)
         at java.awt.DefaultKeyboardFocusManager.typeAheadAssertions(DefaultKeyboardFocusManager.java:840)
         at java.awt.DefaultKeyboardFocusManager.dispatchEvent(DefaultKeyboardFocusManager.java:530)
         at java.awt.Component.dispatchEventImpl(Component.java:3841)
         at java.awt.Container.dispatchEventImpl(Container.java:2024)
         at java.awt.Window.dispatchEventImpl(Window.java:1774)
         at java.awt.Component.dispatchEvent(Component.java:3803)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
         at java.awt.SequencedEvent.dispatch(SequencedEvent.java:93)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:461)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)
    … few things
    -1. If I commit a transaction through the popup dialog the exception doesn’t emerge.
    -2. If I remove the “panelBinding.releaseDataControl(); statusBar.release();” from doDefaultCloseAction() method the exception doesn’t emerge but then I get another well-known exception as I try to reopen the internal frame.
    -3. If I debug doDefaultCloseAction() method step by step the exception doesn’t emerge.
    -4. Finally…. the exception doesn’t suspend the application it just goes on as if nothing has happened (the stack is only displayed on the console).
    I learned about one similar problem here:
    JClient Threading Bug in JUCtrlAttrsBinding?
    but the bug described has been fixed in ver 10.1.3.3.
    I'm using Jdeveloper 10.1.3.3
    So, please ...please…please help me overcome it.
    Best regards. Alex.
    Edited by: Timin on Mar 31, 2009 1:52 PM

    Sorry for being a bit annoying...
    But .... no one has answered my question yet......though you promised...
    Eventually I’ve somehow solved the trouble by replacing the “ panelBinding.releaseDataControl ” with
    “ panelBinding.release(DCDataControl.REL_VIEW_REFS)
    panelBinding.getBindingContext().remove(panelBinding.getName());”
    In the doDefaultCloseAction() method
    it seems like it works good now.
    I reconstructed a bit my code
    Now I’m invoking the internal frames this way:
    private void jMenuDeptVoc_actionPerformed(ActionEvent e) {
    FormCreateDeptView deptVoc = new FormCreateDeptView();
    this.getJMenuDeptVoc().setEnabled(false);
    deptVoc.setBindingContext(panelBinding.getBindingContext());
    this.deskTopPane.add(deptVoc);
    I looked through the following how to:
    http://www.oracle.com/technology/products/jdev/howtos/10g/jcmultiform/index.html
    there is an additional method there, which is invoked before creating a new frame where the binding container for the panel binding is created:
    private void createDetailBinding()
    String detailBCName = "DetailFormUIModel";
    if (panelBinding.getBindingContext().get(detailBCName) == null)
    DCBindingContainerDef bcdef = (DCBindingContainerDef)JUMetaObjectManager.getJUMom().findLoadedObject("sample.DetailFormUIModel");
    DCBindingContainer bc = bcdef.createBindingContainer(panelBinding.getBindingContext());
    bc.setName(detailBCName);
    panelBinding.getBindingContext().put(detailBCName, bc);
    But since createBindingContainer(BindingContext) method has been deprecated in 10.1.3 i skipped this step.
    Nevertheless my program is working now I still wonder if the way I’m doing it is right.
    Thanks. Alex.
    Edited by: Timin on Apr 2, 2009 8:28 AM

  • ADF Swing Deployment problem

    Hi,
    I have an ADF Swing project completed.
    I can run my application from Jdeveloper 10.1.3.3 successfully.
    Now we are ready to go to production.
    I want to generate a simple JAR file which can be called like - java -jar MyApp.jar
    To generate MyApp.jar:
    1) I have created a new group in the deployment profile file and specify to add the Manifest.
    2) I added all the jars found in my application log file (the logs when jdev run my app.).
    3) I Specify the full path to my MainForm.class
    4) I have added all my classes
    5) Finally I generated to JAR from jdeveloper
    6) I copied the MyApp.jar into the JDK\bin folder of my Jdeveloper (to avoid potential java version conflict)
    Problem: When I try to run my app from the JDK\bin folder with java -jar MyApp.jar, I got the error Exception in thread "main" java.lang.NoClassDefFoundError: .....
    My question is : Does anybody either successed in deploying an ADF Swing application using Jdeveloper. If yes, how?
    I have read dozen of articles from this forum, nobody seemed to successed deploying ADF Swing application.
    Thanks.
    houevoton.

    Gentlmen, thank very much.
    I have made a big progress.
    First, I have deploy a simple form based on Steve's scenario. It works fine. I learn from this the role of each type of File Group in a deployment profile.
    I also read and dowload the following show case http://verveja.footsteps.be/~verveja/files/oracle/JarStuffThread615655-v0.01.zip
    It works fine. I get how to include an external jar in my deployment file.
    However, I am still having a small problem with my generated JAR.
    In fact my workspace has 3 projects.
    1- AppUtils.jpr contains my utility classes (date utilities, system constants, etc.)
    2- Model.jpr contains BC entities, views objects and the AppModule.
    3- View.jpr where my forms and panels are.
    All those 3 projects are in the same workspace, which is slightly diffrent from the example of the show case above.
    I created a deployment profile and add two File Groups:
    - The first group is simple "Packaging" group and I check all utilities classes required in my application.
    - The second one is a "Dependency Analysis" group following process described by Steve.
    When I generate and run MyApp.jar, I get error [b]JBO-30003: The application pool (full.path.AppModuleLocal) failed to checkout an application.
    Since yesterday I was struggling with this. I am not able to understand why this message.
    My AppModule is well configured with credentials to connect to the target database. I tested it and it is ok.
    I can run the application from within Jdeveloper without trouble.
    Once again, I need your help.
    Thank in advance.
    houevoton.

  • Where can I find Java 1.5 swing (JTabbedPane class) source code

    I've installed Java 1.5 and 1.6 JDK's on my PC. I was told that after you do this there is a jar file that contains Sun's Java source code (the .java files) that gets installed along with the JDK. However, I have not been able to find this jar file. Does anyone know where I can find the Sun Java 1.5 Swing library source files? Specifically I am trying to edit/modify the JTabbedPane class.

    I find the src.zip on my work PC, where I installed the 1.5/1.6 JDK back in 2007. Looks like when I installed the JDK's on my home PC that I did not get the src.zip file??? Anyway thanks for your help.

  • Javax.swing.GroupLayout - problem

    Hi
    Puzzling problem has occurred when developing the same application on different PC�s and using the same IDE (Netbeans 5.5) on both.
    The problem is that the �javax.swing.GroupLayout� class is being used when inserting netbeans GUI components on one of the PC�s. However, the other PC uses �org.jdesktop.layout.GroupLayout� and generates an error when trying to compile the �javax.swing.GroupLayout� components. It cannot find the javax.swing.GroupLayout� class.
    The jdk is jdk 6 for both.
    Can anyone shed any light on this?
    Regards
    GB

    Did you check the project properties?
    Project properties | Categories: Libraries --> Java Platform: JDK 1.6
    (javax.swing.GroupLayout works only with 1.6)

  • Swing Worker Problems

    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class QuoteClientApplet extends JApplet
    implements ActionListener {
    private static boolean DEBUG = false;
    private InetAddress address;
    private JTextField portField;
    private JLabel display;
    private JButton sendButton;
    private JProgressBar progressBar;
    private DatagramSocket socket;
    private String host;
    private static final int MAX_NUM_CHARS = 256;
    private static final int TIMEOUT = 500; //time out after 1/2 a second
    private static String sendButtonText = "OK";
    private QuoteGetter quoteGetter;
    public void init() {
    //Initialize networking stuff.
    host = getCodeBase().getHost();
    try {
    address = InetAddress.getByName(host);
    } catch (UnknownHostException e) {
    System.err.println("Couldn't get Internet address: Unknown host");
    // What should we do?
    try {
    socket = new DatagramSocket();
    socket.setSoTimeout(TIMEOUT);
    } catch (IOException e) {
    System.err.println("Couldn't create new DatagramSocket");
    return;
    //Set up the UI.
    //Execute a job on the event-dispatching thread:
    //creating this applet's GUI.
    try {
    SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
    createGUI();
    } catch (Exception e) {
    System.err.println("createGUI didn't successfully complete");
    private void createGUI() {
    JPanel contentPane = new JPanel(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    int numColumns = 3;
    JLabel l1 = new JLabel("Quote of the Moment:", JLabel.CENTER);
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.SOUTH;
    c.gridwidth = numColumns;
    contentPane.add(l1, c);
    display = new JLabel("(no quote received yet)", JLabel.CENTER);
    display.setForeground(Color.gray);
    c.gridy = 1;
    c.gridwidth = numColumns;
    c.anchor = GridBagConstraints.CENTER;
    c.weighty = 1.0;
    c.fill = GridBagConstraints.HORIZONTAL;
    contentPane.add(display, c);
    JLabel l2 = new JLabel("Enter the port (on host " + host
    + ") to send the request to:",
    JLabel.RIGHT);
    c.gridy = 2;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.SOUTH;
    c.weighty = 0.0;
    c.fill = GridBagConstraints.NONE;
    contentPane.add(l2, c);
    portField = new JTextField(6);
    c.gridx = 1;
    c.weightx = 1.0;
    c.insets = new Insets(0,5,0,0);
    c.fill = GridBagConstraints.HORIZONTAL;
    contentPane.add(portField, c);
    sendButton = new JButton(sendButtonText);
    c.gridx = 2;
    c.weightx = 0.0;
    c.fill = GridBagConstraints.NONE;
    contentPane.add(sendButton, c);
    progressBar = new JProgressBar();
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = numColumns;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.insets = new Insets(5,0,5,0);
    contentPane.add(progressBar, c);
    portField.addActionListener(this);
    sendButton.addActionListener(this);
    //Finish setting up the content pane and its border.
    contentPane.setBorder(BorderFactory.createCompoundBorder(
    BorderFactory.createLineBorder(Color.black),
    BorderFactory.createEmptyBorder(5,20,5,10)));
    setContentPane(contentPane);
    private class QuoteGetter extends
    org.jdesktop.swingworker.SwingWorker<String, String> {
    int port;
    InetAddress address;
    public QuoteGetter(int port, InetAddress address) {
    this.port = port;
    this.address = address;
    @Override
    public String doInBackground() {
    DatagramPacket packet;
    byte[] sendBuf = new byte[MAX_NUM_CHARS];
    packet = new DatagramPacket(sendBuf, MAX_NUM_CHARS, address, port);
    try { // send request
    if (DEBUG) {
    System.out.println("Applet about to send packet to address "
    + address + " at port " + port);
    socket.send(packet);
    if (DEBUG) {
    System.out.println("Applet sent packet.");
    } catch (IOException e) {
    System.err.println("Applet socket.send failed:\n"
    + e.getStackTrace());
    return null;
    packet = new DatagramPacket(sendBuf, MAX_NUM_CHARS);
    try { // get response
    if (DEBUG) {
    System.out.println("Applet about to call socket.receive().");
    socket.receive(packet);
    if (DEBUG) {
    System.out.println("Applet returned from socket.receive().");
    } catch (SocketTimeoutException e) {
    System.err.println("Applet socket.receive timed out.");
    //Should let the user know in the UI.s
    return null;
    } catch (IOException e) {
    System.err.println("Applet socket.receive failed:\n"
    + e.getStackTrace());
    return null;
    String received = new String(packet.getData());
    StringBuffer data = new StringBuffer(received);
    //Hack alert! Assuming the last character is garbage, rid
    //this string of all garbage characters.
    int firstGarbage = data.indexOf(Character.toString(
    received.charAt(MAX_NUM_CHARS - 1)));
    if (firstGarbage > -1) {
    data.delete(firstGarbage, MAX_NUM_CHARS);
    return data.toString();
    //Once the socket has been read, display what it sent.
    protected void done() {
    if (DEBUG) {
    System.out.println("SwingWorker is done.");
    progressBar.setIndeterminate(false);
    try {
    String s = get();
    if (DEBUG) {
    System.out.println("get() returned \"" + s + "\"");
    if (s != null) {                   
    //Display the text.
    display.setForeground(Color.gray);
    display.setText(s);
    } else {
    display.setForeground(Color.red);
    display.setText("Read failed (see console for details).");
    } catch (Exception ignore) { }
    //invoked on the event-dispatching thread
    private void doIt(int port) {
    //Listen to the port on a background thread to avoid
    //tying up the GUI.
    quoteGetter = new QuoteGetter(port, address);
    quoteGetter.execute();
    display.setForeground(Color.gray);
    display.setText("Reading port #" + port);
    public void actionPerformed(ActionEvent event) {
    try {
    int port = Integer.parseInt(portField.getText());
    progressBar.setIndeterminate(true);
    doIt(port);
    } catch (NumberFormatException e) {
    //No integer entered.
    display.setForeground(Color.red);
    display.setText("Please enter a number in the text field below.");
    public void destroy() {
    //destroy the DatagramSocket?
    if (socket != null) {
    socket.close();
    //Set up the UI.
    //Execute a job on the event-dispatching thread:
    //creating this applet's GUI.
    try {
    SwingUtilities.invokeAndWait(new Runnable() {
    public void run() {
    getContentPane().removeAll();
    } catch (Exception e) { }
    This code is from:
    http://java.sun.com/docs/books/tutorial/deployment/applet/clientExample.html
    and I get the error (when I compile):
    package org.jdesktop.swingworker does not exist
    Now, I've reinstalled the latest jdk and jde, and yet I still get this problem. I've taken a class on java, however, it didn't cover anything like this, so I'm a bit confused. Please help :(

    Why do you have this in your code?
    private class QuoteGetter extends
    org.jdesktop.swingworker.SwingWorker<String, String> {The class you probably need is javax.swing.SwingWorker and its import is covered by your package import statementimport javax.swing.*;To post code, use the code tags -- [code]Your Code[/code]will display asYour CodeOr use the code button above the editing area and paste your code between the {code}{code} tags it generates.
    db

  • JTabbedPane problems

    hi,
    i have a JTabbedPane and i initialize it with 5 tabs as follows
    public class Frame1 extends JFrame
    static JTabbedPane jtp= new JTabbedPane();
    static JList jl;
    static JTextArea jta;
    jtp.setBounds(new Rectangle(1, 192, 336, 308));
    jtp.setBorder(border16);
    jtp.addChangeListener(new mychangelistener());
    for(int i = 0; i < 5; i++) //initialising the tabbed pane with 5 tabs
    JPanel jp= new JPanel();
    jl= new JList();
    jta= new JTextArea();
    JScrollPane jsp1= new JScrollPane();
    JScrollPane jsp2= new JScrollPane();
    jp.setLayout(null);
    jp.add(jsp1, null);
    jp.add(jsp2, null);
    jsp1.getViewport().add(jl, null);
    jsp1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jsp1.setBounds(new Rectangle(6, 5, 315, 165));
    jsp2.getViewport().add(jta, null);
    jsp2.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
    jsp2.setBounds(new Rectangle(6, 176, 315, 80));
    jtp.addTab(tabnames.getText(), jp);
    jtp.setEnabledAt(i, false);
    class mychangelistener implements ChangeListener
    public void stateChanged(ChangeEvent e)
    int x = Frame1.jtp.getSelectedIndex();
    switch(x)
    case 0:
    Frame1.jta.append("tab1");
    break;
    case 1:
    Frame1.jta.append("tab2");
    break;
    the problem i am having is that when tab2 is selected nothing prints in the text area of that tab, it works fine for tab1 tho. i dont think iam referencing the right component by just saying jta.append.. can someone please tell me how to go about doing this?
    thanks
    maulin

    When you post code use the formatting tags so the code is readable. Click on the "Formatting Help" the next time you post a question.
    the problem i am having is that when tab2 is selected nothing prints in the text area of that tab, it works fine for tab1 tho.I don't know how it works for tab 1 since the "jta" variable references the last JTextArea created. Why don't you create an array so you can store all five references to the individual text area.

  • Swings Font Problem

    Sir i used NetBeans mattisse in devolopment of my swings project
    i used a font which are not available in other systems by default we have to install those fonts so that it will reflect in the tool otherwise some default font is visible how to overcome this problem

    If the font is not installed in ur system then load it using createFont method, and distribute it with ur program

  • JRE 1.1 AWT / 1.3 Swing Internationalization Problems. Please Help!!

    This is driving me crazy. I ended up distilling down a bug in a big program to a few lines of code. I was then able to extract that code to a small program to reproduce the problem.
    I am running JRE 1.3 with Swing. But the program I want to run is 1.1 with AWT. (I use a online 1.1 compiler to compile that program.)
    Here is the 1.1 AWT program:
    import java.awt.*;
    import java.awt.event.*;
    import java.util.*;
    import java.lang.*;
    class Awt {
    public static void main(String s[]) {
    Label label = new Label("\u65e5\u672C\u8A9E");
    label.setFont(new Font("MS Gothic", Font.PLAIN, 24));
    Frame frame = new Frame();
    frame.add(label);
    frame.pack();
    frame.show();
    When I run it, I get blocks instead of Japanese characters.
    But when I port it to 1.3 and Swing, it displays properly. The code for that is:
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    import java.util.*;
    import java.lang.*;
    class Swing {
    public static void main(String s[]) {
    JLabel label = new JLabel("\u65e5\u672C\u8A9E");
    label.setFont(new Font("MS Gothic", Font.PLAIN, 24));
    JFrame frame = new JFrame();
    frame.getContentPane().add(label);
    frame.pack();
    frame.setVisible(true);
    Can anyone help me figure this out? I don't want to download JRE 1.1 (and replace my 1.3) just for this program. And it would be too cumbersome to rewrite the program into Swing.
    Also, it can't be a font problem because my MS Gothic works in the 1.3 Swing version.
    I have already changed the font.properties.ja file to font.properties.

    You asked this same question 2 hours ago.
    http://forum.java.sun.com/thread.jspa?threadID=608654&messageID=3326676
    Don't clutter the forum by posting multiple questions on the same topic.
    In fact this is you 3rd posting on this topic and you didn't list to point 2 and 3 from my reply in you previous posting, so why should I try helping again.
    By the way you can't compare:
    if (e.getSource() == "one")
    getSource() returns an Object not a String.
    The correct way to test which button was click was given to you in your 4th last posting. So you have at least 4 postings on this topic.
    Now isn't this difficult trying to have a conversation when you have 4 posting going on the same subject?
    Of course you can also read the Swing tutorial on "How to Use Buttons" for another way to test buttons. This solutions allows you to test for a String:
    http://java.sun.com/docs/books/tutorial/uiswing/components/button.html
    However, I recommed the suggest from your 4th last posting.

  • Beginning Swing programming problem

    My classmates and I are trying to write a simple Swing program with a single button and a text field that contains the number of times the button has been pressed since the program started. The problem is that in the ActionPerformed method, any changes to the text field ends up with multiple event errors. It will print the count fine to the command prompt, but not the GUI. Any insight would be greatly appreciated.
    import javax.swing.*;
    import java.awt.event.*;
    import java.awt.*;
    class CounterGUI extends JFrame implements ActionListener
         public int count = 0;
         Container contents = getContentPane();
         JTextField counter;
         final String temp = "Total times pressed: ";
         public CounterGUI()
              final int width = 300;
              final int height = 300;
              setSize(width, height);
              JTextField counter = new JTextField(temp + count);
              counter.setEditable(false);
              JButton clicker = new JButton("Click me!");
              clicker.addActionListener(this);
              clicker.setActionCommand("Click");
              contents.add(counter, "Center");
              contents.add(clicker, "South");
         public void actionPerformed(ActionEvent e)
              String command = e.getActionCommand();
              if(command == "Click")
                   count++;
                   counter.setText(temp + count);     
                   System.out.println(count);
         public static void main(String[] args)
         JFrame f = new CounterGUI();
         f.addWindowListener(new WindowCloser());
              f.setVisible(true);

    Hi Guys,
    The line JTextField counter = new JTextField(temp + count); is declared in the constructor, this means that the field counter is not visible to other methods and you'll get a null pointer exception (NPE) when you try to access the class field counter
    Change to counter = new JTextField(temp + count); Now if you were catching and displaying exceptions you'd notice that this was happening.
    Dave

  • Swing refresh problem

    Hi everyone! This is my first message. And my first doubt...
    I'm developing a Swing app to monitor a device using SNMP. For that my app requests some variables to the MIB perfoming a polling. Each time it receives response a PropertyChangeEvent is fired, a class listens it and invokes refreshing to GUI. That means setting about 30 textFields , do some checks and color some of them depending of received values.
    Well, the polling is a Thread inside the Communication class, it fires the events and "Monitor" class listens and invoke refreshGUI method of the main Frame.
    The problem is that after interacting for a while with the app the refhresh seams to go mad, duplicating the text in some textFields in a "spasmic" way. I don't no if its a Thread issue, events listening or whatever. Maybe its relevant the fact there's a Thread.sleep(100) at the end of refreshGUI() in order to avoid the amount of CPU processing of my app. I think thats a bit sloopy solution <img class="emoticon" src="images/emoticons/confused.gif" border="0" alt="" />
    I haven't attached any code because of the number of classes involved, but if you think it's necessary just say it.
    Excuse my english and lots of thanks!!

    Ok, after doing the things you kindly said to me I'll go one step over and ask...
    How much costs (about CPU processing) setting text and coloring JTextFields?? My poller "order" refreshing every second, so that causes javaw.exe to get about 50 % of CPU and even GUI freezes a bit.
    I mean, is it normal? or Haven't I noticed some sleep or something?
    The refresher is a public of my JFrame, so I supose it's treated by EVT.
    This is the method, which is invoked in a Class.
    public void refreshUI() {
              try {
                   // Settings Panel
                   serialTextField.setText(LpbMonitor.getLpb()
                             .getTttDevUnitHWSerialNumber().getValue());
                   descriptionTextField.setText(LpbMonitor.getLpb()
                             .getTttDevSysDescription().getValue());
                   dsPowerOutTextField.setText(LpbMonitor.getLpb()
                             .getTttTMaxRfPowerSignalActualPowerOut().toString());
                   dsPowerOutCurrentTextField.setText(LpbMonitor.getLpb()
                             .getTttTMaxRfPowerSignalCurrentPowerOut().toString());
                   usGainTextField.setText(LpbMonitor.getLpb()
                             .getTttTMaxRfGainActualGain().toString());
                   // Sets the text for reference mode getting the admin and
                   // oper
                   // status
                   setReferenceModeText();
                   setRfStatusText();
                   // Status Oscillators
                   if (LpbMonitor.getLpb().getOscillatorsStatus() == LPB.ALARM) {
                        oscillatorsStatusTextField.setText("Alarm");
                        oscillatorsStatusTextField.setBackground(Color.RED);
                   } else {
                        oscillatorsStatusTextField.setText("OK");
                        oscillatorsStatusTextField.setBackground(new Color(212, 208,
                                  200));
                   // Temp Status
                   if (LpbMonitor.getLpb().getTttDevChassisSensorOperStatus1().getValue() == LPB.ALARM) {
                        tempStatusTextField.setText("Alarm");
                        tempStatusTextField.setBackground(Color.RED);
                   } else {
                        tempStatusTextField.setText("OK");
                        tempStatusTextField.setBackground(background);
                   // IF Status
                   byte error = 0x0002;
                   byte[] status = LpbMonitor.getLpb().getTttDevSysOperStatus()
                             .getByteValue();
                   if ((status[5] & error) != 0) {
                        ifStatusTextField.setText("Alarm");
                        ifStatusTextField.setBackground(Color.RED);
                   } else {
                        ifStatusTextField.setText("OK");
                        ifStatusTextField.setBackground(background);
                   // Summary Fault
                   if (LpbMonitor.getLpb().getTttDevSysSummaryFault().getValue() == LPB.SYS_SUMMARY_FAULT_ON) {
                        summaryTextField.setText("ON");
                        summaryTextField.setBackground(Color.RED);
                   } else if (LpbMonitor.getLpb().getTttDevSysSummaryFault().getValue() == LPB.SYS_SUMMARY_FAULT_OFF) {
                        summaryTextField.setText("OFF");
                        summaryTextField.setBackground(background);
                   // Monitoring
                   setPowerInMonitoring();
                   setPowerOutMonitoring();
                   setDroTuneMonitoring();
                   setFECurrent();
                   // VIEW / ADVANCED
                   if (advancedCheckBoxMenuItem.isSelected()) {
                        refreshAdvanced();
                   // VIEW / SENSOR VOLTAGES
                   if (ifCheckBoxMenuItem.isSelected()) {
                        refreshIfBoard();
                   // VIEW / ERRORS AND INFORMATION
                   if (activeErrorsCheckBoxMenuItem.isSelected()) {
                        refreshErrors();
                   // VIEW / TEMPERATURES
                   if (temperaturesCheckBoxMenuItem.isSelected()) {
                        refreshTemp();
                   // VIEW / OSCILLATORS
                   if (oscillatorsCheckBoxMenuItem.isSelected()) {
                        refreshOscillators();
                   // ACTIONS / REFERENCE
                   switch (LpbMonitor.getLpb()
                             .getTttTMaxRfFreqReferenceSignalAdminStatus().getValue()) {
                   case (LPB.FREQ_REFERENCE_SIGNAL_ADMIN_STATUS_INTERNAL):
                        internalCheckBoxMenuItem.setSelected(true);
                        externalCheckBoxMenuItem.setSelected(false);
                        break;
                   case (LPB.FREQ_REFERENCE_SIGNAL_ADMIN_STATUS_EXTERNAL_GPS):
                        externalCheckBoxMenuItem.setSelected(true);
                        internalCheckBoxMenuItem.setSelected(false);
                        break;
                   // ACTIONS / RF CONTROL
                   switch (LpbMonitor.getLpb().getTttTMaxRfStatusAdminStatus().getValue()) {
                   case (LPB.STATUS_ADMIN_STATUS_FORCED):
                        onRfCheckBoxMenuItem.setSelected(true);
                        offRfCheckBoxMenuItem.setSelected(false);
                        autoCheckBoxMenuItem.setSelected(false);
                        break;
                   case (LPB.STATUS_ADMIN_STATUS_ENABLED):
                        onRfCheckBoxMenuItem.setSelected(false);
                        offRfCheckBoxMenuItem.setSelected(false);
                        autoCheckBoxMenuItem.setSelected(true);
                        break;
                   case (LPB.STATUS_ADMIN_STATUS_DISABLED):
                        onRfCheckBoxMenuItem.setSelected(false);
                        offRfCheckBoxMenuItem.setSelected(true);
                        autoCheckBoxMenuItem.setSelected(false);
                        break;
                   // ACTIONS / TEST PORT
                   switch (LpbMonitor.getLpb().getTttTMaxRfTestPortControlValue()
                             .getValue()) {
                   case (LPB.TESTPORT_DS):
                        dsTestMenuItem.setSelected(true);
                        xoTestMenuItem.setSelected(false);
                        usTestMenuItem.setSelected(false);
                        break;
                   case (LPB.TESTPORT_US):
                        dsTestMenuItem.setSelected(false);
                        xoTestMenuItem.setSelected(false);
                        usTestMenuItem.setSelected(true);
                        break;
                   case (LPB.TESTPORT_XO):
                        dsTestMenuItem.setSelected(false);
                        xoTestMenuItem.setSelected(true);
                        usTestMenuItem.setSelected(false);
                        break;
              } catch (Exception e) {
                   e.printStackTrace();               
         }Any Idea??
    Excuse me for beeing tedious, but it's really important for me.
    Thanks everyone!

Maybe you are looking for