Double title on JPanel

Hi,
I want to create a JPanel with a border with two titles one on the top-left and other on the bottom-right. Is there a way to do this.
I tried the Compound border with two title borders. But it seems one overlaps on the top of the other.
Is there any solution to show two titles on a border.
RT

I got the answer for what I was looking for.
Just want to post it here.
setBorder(new TitledBorder (
new TitledBorder(
BorderFactory.createEtchedBorder(),
"Hello"),
"World",
TitledBorder.RIGHT,
TitledBorder.BOTTOM));
Thanks
RT

Similar Messages

  • Enabling Double-buffer in JPanel

    Does anyone know how i would enable the double-buffering that JPanel supports. I have heard that it supports that and you have to enable it. If anyone could help i would really appreciate it thanks.
    mdawg

    From the JDK1.2.2 API:
    Constructor Summary
    JPanel()
    Create a new JPanel with a double buffer and a flow layout
    JPanel(boolean isDoubleBuffered)
    Create a new JPanel with FlowLayout and the specified buffering strategy.
    JPanel(LayoutManager layout)
    Create a new buffered JPanel with the specified layout manager
    JPanel(LayoutManager layout, boolean isDoubleBuffered)
    Creates a new JPanel with the specified layout manager and buffering strategy.
    It would appear that double buffering is the default.

  • Repainting JPanels / Memory Allocation

    Hi there! I just wrote a small Programm to test some graphical algorithms using a double-buffered Swing JPanel in a JFrame.
    The Paint method of the JPanel iterates through a Vector drawing the Objects inside. The repaint occurs every 10ms.
    Now when I initially start the program, the Java Interpreter already allocates 11MB of RAM, though I did nothing but initiate the Frame and the Panel.
    After more than 12MB are allocated by adding Objects, all the Objects are suddenly drawn in pure white (though their color-values differ when println'ed) and the movement gets rough.
    I tried to manually run the garbage collector and the runFinalization() method, since the objects are destroyed once they collide, but that had no effect on the allocated RAM. I even explicitly set deleted Objects to null, but that didn't work either.
    Now when I minimize the Frame everything stays the same, but when I bring it in Focus again suddenly several Megs are released.
    So now to the question: What happens when I do this? I thought only the repaint() method would be called, but apparently there's more to that!?
    Could it be that there are old Grpahic contexts are stacking up for some reason? I don't know what to do anymore...

    Here it is, looks a bit weird, but i did my best to
    make it as readable as I could since i used 4-step
    tabs and the forum killed my layout...
    I removed some optional stuff that is definitely not
    related to the problem to make it more readable.
    drawArea=new JPanel()
    { public void paint( Graphics g)
    { Vector newCoords=new Vector();
    Dimension d=drawAreaPane.getSize();
    Enumeration en=balls.elements();
    frameCounter++;
    g.setColor(new Color(0,0,0));
    g.fillRect(0,0,d.width,d.height);                                   
    for(int i=0; en.hasMoreElements();i++)     //Draw
    aw Objects1
    { SEGD_Ball_Crash
    sh b=(SEGD_Ball_Crash)en.nextElement();
    b.updateDimension(d);     //Windowdimension is passed
    ssed to Object for collision checks
    b.checkPos();
    b.move();
    g.setColor(b.getColor());
    //System.out.println(b.getColor());
    g.fillOval(b.location.x-b.radius,
    ius, b.location.y-b.radius, b.radius*2,
    b.radius*2);                    
    collisionCheck(b,g);     //perform collision checks
    ecks between all objects
    if(!b.deleted)               //Abrage auf explodierte B�lle
         newCoords.add(b);
    else {     b=null;      }
    balls=newCoords;
    newCoords=null;
    //Draw Objects 2
    int iterator=0;
    Vector newExplosions=new Vector();
    for(Enumeration enum=explosions.elements();
    ); enum.hasMoreElements();iterator++)
    { Explosion s=(Explosion)enum.nextElement();
    Vector currentParticles=s.getParticles();
    g.setColor(s.getColor());
    for(Enumeration
    tion
    current=currentParticles.elements();current.hasMoreElem
    nts();)
    { Point
    oint thisParticlePoint=(Point)current.nextElement();
    g.fillOval(     thisParticlePoint.x-s.particleSize/2,
    e/2, thisParticlePoint.y-s.particleSize/2,
    s.particleSize, s.particleSize);                    
    currentParticles=null;
    if(!s.deleted)     //don't add deleted explosions
    newExplosions.add(s);
    else {     s=null;     }
    explosions=newExplosions;
    newExplosions=null;
    try{Thread.sleep(15);}catch (InterruptedException
    ion i){};
    g=null;
    repaint();
    };1) What jdk are you using? I would recommend using 1.4.1 if you can.
    2) I would cast the Graphics object to Graphics2D and use setPaint instead of setColor.
    3) As a test, try using Color.red (anything other than new Color(0,0,0)) when painting your background, just to make sure colors work.

  • Change the title of a TitledBorder

    I have a titledBorder and set an initial title.
    JPanel         panel = new JPanel();
    Border         etched = BorderFactory.createEtchedBorder();
    TitledBorder   title  = BorderFactory.createTitledBorder(etched, "myPanelNameEnglish");
    title.setTitleJustification(TitledBorder.LEFT);
    panel.setBorder(title);If the user change the language I also want change the title of the TitledBoarder:
    TitledBorder tb = (TitledBorder) panel.getBorder();
    tb.setTitle("myPanelNameInFrench");I realize it for all buttons, labels etc. but the title of the TitledBoarder.
    Is it possible to change it's title? And how? Please help me :)

    Sure you can change the title on the fly.
    Here's some code that shows how it is done:
    final JFrame f = new JFrame( "Test Frame" );
    final JPanel p = new JPanel();
    p.setBorder( BorderFactory.createTitledBorder( "This is a title" ) );
    p.setPreferredSize( new Dimension( 400, 400 ) );
    JButton b = new JButton ( "Click me" );
    b.addActionListener( new ActionListener(){
         @Override
         public void actionPerformed(ActionEvent e) {                    
              ((javax.swing.border.TitledBorder)p.getBorder()).setTitle( "Nother title" );
              p.revalidate();
              p.repaint();
    p.add( b );
    f.getContentPane().add( p );
    f.setSize( 500, 500 );
    f.setVisible( true );
    f.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );     

  • Encore encoding rolling titles incorrectly.

    I've got an approximately 1 hour video - a dance recital. I've got rolling titles at the end stretched out to 3% speed, to cover an entire song. The titles are off to the right side and on the left there is a montage of clips in a resized frame.
    Snap below. And video inserted.
    The video in this montage has no filters, just third party transitions.
    It's done this for MP4 and DVD encoding.... but only on a two pass. One pass encodes fine.
    Here are the encoding specs:
    Mpeg2-DVD : NTSC match attributes
    2 pass VB, use previews.
    The MPeg4 was the Vimeo HD preset with a 2 pass and use previews.
    I didn't change any other settings.
    When I encode with one pass the titles are correct. If I go to two pass, you see what happens, both in this still and in the video clip.
    Anyone understand why this is happening?
    Is it usually a big compromise in quality to only have one pass?
    Thanks for all your help.
    Jessica

    ok....to make matters worse......the video that's on Vimeo...actually plays correctly. Huh?????
    You can see that the thumbnail has the double titles...but, when you play it, it's ok. It's not ok if I play it with VLS or Media player on my machine. What the heck could be happening????
    I'm not producing a one pass, but I'm going to put the test clip in Encore and see how it produces/plays through that..
    J

  • Retrieve data from SQL database and put into a table

    Hi all, i encountered this error while trying to create a table in 1 of my panels:
    C:\Documents and Settings\L311c01\Desktop\FYPJ Java2\RFIDLogistics.java:25:{color:#ff0000} cannot find symbol
    symbol : class ResultSetTable
    {color}location: class jdbc_bible.part2.RFIDLogistics
    private static ResultSetTable model = new ResultSetTable();
    ^
    C:\Documents and Settings\L311c01\Desktop\FYPJ Java2\RFIDLogistics.java:25: {color:#ff0000}cannot find symbol
    symbol : class ResultSetTable
    {color}location: class jdbc_bible.part2.RFIDLogistics
    private static ResultSetTable model = new ResultSetTable();
    I understand that " cannot find symbol class ResultSetTable means that i need to import something which has this ResultSetTable. I suppose my imports are sufficient and i think the error is with the package that i included.
    This package was taken from an example in a book named java database programming bible, so i assumed it is reliable and i use it for my insert statement, which had a DataInserter.
    Could someone plz help me with this? Thanks alot in advance.
    Here are the codes:
    {color:#ff0000}package jdbc_bible.part2;{color}
    import java.sql.*;
    import javax.swing.*;
    import java.util.Vector;
    import javax.swing.table.AbstractTableModel;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.io.*;
    import java.util.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import sun.jdbc.odbc.JdbcOdbcDriver;
    public class RFIDLogistics extends JFrame{
    //Components
    // public SimpleClock clock;
    private static JTable jt;
    private static ResultSetTable model = new ResultSetTable();
    some codes
    {color:#ff0000}try
    {{color}
    {color:#ff0000} DataInserter inserter = new DataInserter();
    String SQLCommand = "INSERT INTO " + flstr + " (Item_ID,Location_ID) VALUES ('"+Item_ID1+"','"+Location_ID1+"')";
    String SQLCommand2 = "UPDATE Location SET Item_ID = '"+Item_ID1+"' WHERE Location_ID = '"+Location_ID1+"'";
    inserter.execute(SQLCommand);
    inserter.execute(SQLCommand2);
    {color} JOptionPane.showMessageDialog(null, "Successful!");
    catch(ClassNotFoundException f)
    f.printStackTrace();
    catch(SQLException f)
    f.printStackTrace();
    some codes
    public JPanel rightPanel() {
    JPanel rightPanel = new JPanel();
    rightPanel.setLayout(new BoxLayout(rightPanel, BoxLayout.Y_AXIS));
    //Forklift title Panel
    JPanel panel6 = new JPanel();
    panel6.setBorder(new TitledBorder(""));
    panel6.setPreferredSize(new Dimension(192,33));
    panel6.add(forkliftDetails);
    //Forklift 1 Panel
    {color:#ff0000} JPanel panel7 = new JPanel();
    panel7.setBorder(new TitledBorder("Forklift 1"));
    panel7.setPreferredSize(new Dimension(192,120));{color}
    {color:#ff0000} String query = "SELECT * FROM Forklift1";
    try{
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:RFID Logistics");
    PreparedStatement pstmt = con.prepareStatement(query);
    ResultSet rs= pstmt.executeQuery();
    // display the data in jtable
    jt = new JTable();
    model.setResultSet(rs);
    jt.setModel(model);
    catch(ClassNotFoundException sqle){
    System.out.println(sqle);
    }catch(SQLException sqle){
    System.out.println(sqle);
    panel7.add(itemDetail1);
    itemDetail1TextField.setEditable(false);
    panel7.add(itemDetail1TextField);
    panel7.add(locationDetail1);
    locationDetail1TextField.setEditable(false);
    panel7.add(locationDetail1TextField);
    panel7.add(jt);
    {color}..
    //Main Method
    public static void main(String args[]) {
    RFIDLogistics app = new RFIDLogistics();
    app.setFrame();
    app.setResizable(false);
    app.setDefaultCloseOperation(EXIT_ON_CLOSE);
    app.setSize(1024,676);
    app.setLocation(0,60);
    app.setVisible(true);
    If you would like to try if my table can extract, here are the sample codes, just change ur database name which is highlighted in green, and the table name in blue.
    Codes:
    import java.sql.*;
    import javax.swing.*;
    import java.util.Vector;
    import javax.swing.table.AbstractTableModel;
    import java.awt.*;
    import java.awt.event.ActionListener;
    import java.awt.event.ActionEvent;
    import java.io.*;
    import java.util.*;
    import javax.swing.event.*;
    import java.awt.event.*;
    import javax.swing.border.*;
    import sun.jdbc.odbc.JdbcOdbcDriver;
    public class sample1{
    private static JFrame frm;
    private static JTable jt;
    private static ResultSetTable model = new ResultSetTable();
    public static void main(String args[]){
    String query = "SELECT * FROM {color:#00ccff}Forklift1{color}";
    try
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection con = DriverManager.getConnection("jdbc:odbc:{color:#00ff00}RFID Logistics{color}");
    PreparedStatement pstmt = con.prepareStatement(query);
    ResultSet rs= pstmt.executeQuery();
    // display the data in jtable
    jt = new JTable();
    model.setResultSet(rs);
    jt.setModel(model);
    frm = new JFrame("Sample");
    frm.setSize(400,400);
    frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frm.add(jt);
    frm.setVisible(true);
    }catch(ClassNotFoundException sqle){
    System.out.println(sqle);
    }catch(SQLException sqle){
    System.out.println(sqle);
    Could someone plz help me with this? Thanks alot in advance.

    public JTable populateTable()
      String[] colNames = new String[] {"ID","NAME","SURNAME"};
      return new JTable(getSQLData(), colNames);
    public Object[][] getSQLData()
      stmt = conn.createStatement();
      ResultSet rs = stmt.executeQuery("SELECT [ID], [NAME], [SURNAME] FROM [USERS]");
      Object[][[] out = new Object[rs.getFetchSize()][3];//Not sure on getFetchSize but it should work
      int i = 0;
      while(rs.next())
        out[0] = rs.getInt(1);
    out[i][1] = rs.getString(2);
    out[i++][2] = rs.getString(3);
    return out;
    The above code will create a JTable with the data retrieved from the DB                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Sharing tags from existing library to re-burned music

    I am reburning all my CDs as AIFF files for use in Sonos sound system. I have an existing set of .m4a files from the first time I burned everything. 2 things I am not smart enough to know how to do: I would like an automated method to make all the metadata tags on the new burns match my old, hand-edited tags on the .m4a files. Also, I would like to "divide up" my existing library into 2 pieces so that my .m4a and .aif files are completely separated. Basically just 'cuz it drives me crazy to look at all the doubled titles...
    Any thanks with either would be appreciated!

    am reburning all my CDs as AIFF
    Do you mean reRIPping? RIP is to get files off an audio CD. Burn means to create an audio CD as in Burn with the laser.
    I would like to "divide up" my existing library into 2 pieces so that my .m4a and .aif files are completely separated.
    I suggest you create new library only for the AIFF files. Hold the Option key and launch iTunes then select *Create library*.
    Select somewhere and name it *iTunes AIFF library* (or something) then use that to RIP the CDs to AIFF.

  • Flash update messed up FF Add-ons and the Open New Tab button.

    FF told me that I needed to update Flash, so I said OK. Whereupon all of my FF Add-ons disappeared. Seems that FF needed to check with the mother ship to find out if everything were compatible with this new Flash update--but the mother ship was not available (this has happened several times).
    Why didn't FF check on the compatibility issues BEFORE getting the Flash update?!
    I will remove Flash (did this in the past, and the lost functionalities were no big deal). I will also change the settings on FF so that the program won't do this again. (I periodically go see about FF updates myself and try to sit on FF while the updates are being done.)
    BTW ... I had FF set to NO DOWNLOAD/UPDATE anything until/unless I have the OK. The past few weeks, I've gotten constant notes from FF telling me to get FF6.0. I was almost ready--but not quite ready--and yesterday FF updated itself. NO OK from me.
    As I type this, I've finally gotten all of my FF Add-ons and other mods back. And it looks like my bookmark tabs are all squared-away again, too. (The AddNewTab button completely disappeared.)
    So, this is no longer a question for you that could use an answer. Instead, I'd like you to pass my frustrations along to the development crew. I HATE the uncertainty/instability of my Firefox Add-ons and Stylish mods. (I'd rather just skip them.)
    I understand that the Add-ons are not the work of Mozilla (not like the browser program itself, anyway) and that the job of getting everything to work together must be insanely difficult. So I'm not wanting to complain about the compatibility hassles here--I'm complaining about the need to watch FF carefully to make sure FF doesn't jump up and do something that I don't want. That and the fact that I have to remember that FF will change my system BEFORE checking to see if it's going to make a mess for me.
    I only recently returned to Firefox and started using some of the Add-ons again. I love them. But I don't think I'll ever use more than 6 or so Add-ons because of the constant problems with updates like this mess today with Macropedia's Flash. The one thing I don't want in a browser is problems.
    Thanks for your attention here ...
    Jack

    I'm sorry to hear that you have so many issues. What version of Firefox were you using before?
    The double title bar issue has been identified as an issue with the Tax Mix Plus extension but it doesn't affect everyone, it's an interaction with something else (not exactly clear what, although Norton Toolbar was mentioned in one thread).
    There is a new version available that you could try. If Firefox is stable enough to do it...
    orange Firefox button (or Tools menu) > Add-ons > "gear" icon > Check for Updates
    If your beta version won't update, you could try installing [https://addons.mozilla.org/en-us/firefox/addon/tab-mix-plus/ from the add-ons site].
    More generally, could I suggest disabling as many extensions as you can live without for 24 hours, and re-enable them gradually? This should help isolate interactions between them. As you know, you can do that here:
    orange Firefox button (or Tools menu) > Add-ons > Extensions category
    Finally, regarding your old session, if you haven't closed Firefox, you might find a sessionstore.bak file in your profile folder that contains your old session. To easily access that folder, try
    Help > Troubleshooting Information > "Show Folder" button
    Grab a copy of that file and save it somewhere outside the folder because it is overwritten when you close Firefox. Got to run, but if you find one with an appropriate date, someone can help you restore it.

  • DrawString from ArraryList Problem

    First off, I am very to this forum, so if this is not the correct forum, please advise, (continue to have issues with this one).
    I'm a current Java1 student working on the final project for the year. Not looking to have answer provided but simply looking for a direction to move toward the issue I'm having.
    Project involves creating a digital signature, (a crude version of the approval pads you sign with electronic pen at Home Depot, Lowes, 7-11, you get the picture). The major difference is that we are signing the pad with our mouse just to show functionality.
    Problem is: When mouseReleased is invoked after signing one's first name and mousePressed is invoked at the start of the last name, a connector line is drawn from end of first name to beginning of last name. I am looking to have a new word started when mouseReleased is invoked.
    Below is the code pertinent to this part of the program, if more is needed let me know.
    Any help on this would be greatly appreciated.
    // Main OrderPanel Class
    class MainPanel extends JPanel
         //Constructor for main OrderPanel
         public MainPanel()
              sigPoints = new ArrayList<Point>();
              current = null;
              pressed = false;
              System.out.println(pressed);
              setLayout(new BorderLayout());
              northPanel = new JPanel();
              northPanel.setLayout(new GridLayout(2,1));
              logoLabel = new JLabel("Big Dog Hardware - Let's Build Something Today!", SwingConstants.CENTER);
              logoLabel.setFont(new Font("Arial", Font.BOLD, 16));
              logoLabel.setForeground(Color.BLUE);
              northPanel.add(logoLabel);
              approveAmount = (double) (Math.random() * 500);
              add(northPanel, BorderLayout.NORTH);
              southPanel = new JPanel();
              addButton("Approve");
              addButton("Clear");
              addButton("Close");
              add(southPanel, BorderLayout.SOUTH);
              //Topping Checkbox and Beverage checkbox create
              centerPanel = new JPanel();
              centerPanel.setLayout(new GridLayout(1,1));
              centerPanelComponent pad = new centerPanelComponent();
              centerPanel.add(pad);
              add(centerPanel, BorderLayout.CENTER);
          class centerPanelComponent extends JComponent implements MouseMotionListener
              public centerPanelComponent()
              addMouseListener(new MouseHandler());
              this.addMouseMotionListener(this);
              public void paintComponent(Graphics g)
                   Graphics2D graphic = (Graphics2D) g;
                   Rectangle2D signPad = new Rectangle2D.Double(47,50,400,75);
                   graphic.setPaint(Color.BLUE);
                   Font sigFont = new Font("Forte", Font.BOLD,26);
                   graphic.setFont(sigFont);
                   String X_Mark = "X";
                   graphic.drawString(X_Mark,21,123);
                   DecimalFormat dollar = new DecimalFormat("$0.00");
                   Font totalFont = new Font("Arial", Font.BOLD,12);
                   graphic.setFont(totalFont);
                   if (select != 1001)
                        String total = "Your Approval is Required for the Total Amount of: " + dollar.format(approveAmount);
                        graphic.drawString(total, 75, 30);
                   else
                        String total = "You Are Approved for the Total Amount of: " + dollar.format(approveAmount);
                        graphic.drawString(total, 100, 30);
                   graphic.draw(signPad);
                   if (sigPoints.size() > 1)
                        Point previousPoint = sigPoints.get(0);
                        for (int i = 1; i < sigPoints.size(); i++)
                             Point thisPoint = sigPoints.get(i);
                             graphic.drawLine(previousPoint.x, previousPoint.y, thisPoint.x, thisPoint.y);
                             previousPoint = thisPoint;
              public void mouseDragged(MouseEvent event)
                   Point a = event.getPoint();
                   sigPoints.add(a);
                   this.repaint();
              public void mouseMoved(MouseEvent event)
                   private class MouseHandler extends MouseAdapter
                        public void mousePressed(MouseEvent event)
                             if(event.getModifiersEx() == event.BUTTON1_DOWN_MASK)
                             pressed = true;
                             System.out.println(pressed);
                        public void mouseReleased(MouseEvent event)
                             if(event.getModifiersEx() != event.BUTTON1_DOWN_MASK)
                             pressed = false;
                             System.out.println(pressed);
         public void addButton(final String label)
              JButton button = new JButton(label);
              button.addActionListener(new ActionListener()
                        public void actionPerformed(ActionEvent event)
                             String selection = label;
                             if (selection == "Approve")
                                  if (sigPoints.size() < 1)
                                  JOptionPane.showMessageDialog(null, "You must sign the pad to authorize approval", "Approval Error", JOptionPane.PLAIN_MESSAGE);
                                  select = event.getID() +1;
                                  select = event.getID();
                                  repaint();
                             if (selection == "Clear")
                                  select = event.getID()+ 1;
                                  sigPoints.clear();
                                  repaint();
                             if (selection == "Close")
                                  select = event.getID() + 1;
                                  System.exit(0);
              southPanel.add(button);
         private ArrayList<Point> sigPoints;
         private Point current;
         private JLabel logoLabel;
         private JLabel approvalLabel;
         private JLabel approvedLabel;
         private double approveAmount;
         private JPanel northPanel;
         private JPanel southPanel;
         private JPanel centerPanel;
         private DecimalFormat dollar;
         private centerPanelComponent pad;
         private String total;
         private int select;
         private boolean pressed;
    }     

    Switch to a new array list. Or you have to have a state machine track that you are signing your last name. What is happening is that you are just adding a new point to the existing array, so you naturally draw a line from the last point to the next point--that is the logic you use all the way though to generate your signature. This seems to work for you, but you have a mouse release, you need to go to the next state, that is, to the last name, you do this with another ArrayList to hold the data for the last name. You'll have to amend your paint logic to take in:
    State: 0 -- clear
    State: 1 -- getting first name
    State 2 -- have first name and getting second name
    state 3 -- complete all is done.
    Unless you want to accept signatures that have multiple breaks like mine does... I have 5 sections on my signature. In that case you need to just keep on collecting new point set data until they click done.

  • JDialog not coming to front in Linux

    Hello,
    I'm writing an application that needs to show a dialog requesting user input
    with a large set of rather complicated options several times, where the user needs to make a small change each time the dialog is shown. My code looks more or less like this:
    // create a modal dialog
    JDialog controlDialog = new JDialog(parent,title,true);
    JPanel contentPanel = new JPanel()
    // set up all the necessary inputs and buttons on the panel
    // add the panel to the dialog
    controlDialog.getContentPane.add()
    // a loop to get the data
    for (int i=0; i<nPoints; i++) {
    controlDialog.toFront();
    // stop and get the user input
    controlDialog.show();
    // process the results
    }Under Windows, this does what I think it should - it shows the dialog 10 times, each time on top of all other windows. On Linux, it does not. The first time the dialog comes up on top. The next (and all the other times) it is at the bottom, hidden behind all the other windows in the screen, which is highly inconvenient. I'm using Sun JDK1.3.1 on Redhat Linux 7.0 with Gnome. What's wrong?
    I can of course re-create the dialog every time, but given the number of inputs on it, saving and restoring its state is more trouble than I would like to deal with.
    Thanks,
    Myrosia

    I had a problem with this in the past and the issue was with the dialog's constructor with respect to the 'Parent Component'. In my experience the toFront() method only pertains to the component used when constructing the dialog. So if during the course of your user's input the dialog apears over more than one component (Frame/dialog) then the toFront() method may not work.
    I had to resort to re-creating my dialog for each different frame/dialog it needed to appear over. This was no problem for me since my dialog was not very busy and it needed no state to be saved but I can understand how it would be a problem for you.
    In my application there are two or more JFrame's visible at once and the dialogs with JFrame 1 as a parent aloways apear over JFrame 1 but are hidden by JFrame 2 and visa-versa. This seems to support my theory.
    Again, in my experience, the only way to ensure a dialog apears on top of your application is to make sure that the component used as "Parent" in the Dialog's constructor is the component currently in control when the dialog needs to appear.

  • How can i pass variables between classes?

    Hi.
    i have three classes and i need use a variable from 'Battleship' and use it in 'BattleWindow', these summaries of the classes, if anyone could give me a solution without editing it too much it would be greatly appreciated
    public class Ship{
    public Ship(){
    int missilesLeft;
    int shots = 10;
    for (int i=0;i<8;i++) {
         missilesLeft = shots - 1;
    //Panel
    public class PanelWindow{
         public static void main (String [] args) { 
         System.out.println(missilesLeft.Ship);
    Andrew

    i still can get it to work.. but i think that you got me quite close;
    this is where i need to get missilesLeft from
    //BattleShip
    public void mouseClicked(MouseEvent e){
         tries--;
         for (int i = 0; i < 8; i++){
          for (int j = 0; j < 8; j++){
           if (e.getSource().equals(buttons[i][j]) && ship[i][j] == true){
            buttons[i][j].setBackground(new Color(80,80,80));
            hit++;
            System.out.println(hit+" "+total);
           else if (e.getSource().equals(buttons[i][j]) && ship[i][j] == false){
            buttons[i][j].setBackground(new Color(0,0,255));
         //Win
          if (isWin()){
           int hits = 64 - tries;
           int misses = hits- hit;
           int score = ((tries+hit)/misses)*64;
           missilesLeft = tries - 30;
           mis = missilesLeft;
           JOptionPane.showMessageDialog(this, "You WIN!\n \nMissiles used: "+hits+"\nMissiles left: "+missilesLeft+"\nHits: "+hit+"\nMisses: "+misses+"\nScore: "+score );
         //Game Over
         if (isGameOver()){
           JOptionPane.showMessageDialog(this, "  GAME OVER!!\n*******************\nYou have run out of missiles!\nTRY AGAIN");
    //BattleWindow
    private void build(){
              main = new JPanel(new BorderLayout());
              title = new JPanel(new FlowLayout(FlowLayout.CENTER));
              right= new JPanel(new FlowLayout(FlowLayout.CENTER));
              left = new JPanel(new FlowLayout(FlowLayout.CENTER));
              bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));
              displayField = new JTextField("000", 8);
              displayField.setEditable( false );
              b = new Battleship();
              JLabel t = new JLabel("Battleship Potemkin");
              Font myFont =  new Font("Arial",Font.BOLD,32);
              t.setFont(myFont);
              title.add(t);
              help = new JButton("Help");
            exit = new JButton("Quit");     
            help.setFont(new Font("Arial", Font.BOLD, 17));
            exit.setFont(new Font("Arial", Font.BOLD, 17));
            displayField.setFont(new Font("Arial", Font.BOLD, 22));
              main.add(title,BorderLayout.NORTH);
              main.add(left,BorderLayout.WEST);
              main.add(right,BorderLayout.EAST);
              main.add(bottom,BorderLayout.SOUTH);
              main.add(b,BorderLayout.CENTER);
             this.add(main);
              help.addMouseListener(this);
              exit.addMouseListener(this);
              bottom.add(displayField);
              bottom.add(help);
              bottom.add(exit);
              setSize(500,600);
              setResizable(false);
              String aString = Integer.toString(bob);
              displayField.setText(displayField.getText() + bob);
              //displayField.setText("bob");
              }the variable bob in must have the same value as missilesLeft
    thank you

  • Rendering of tab row and pages is totally messed up when I add/remove/scroll through tabs

    After upgrading to 4b9 from 4b8, the rendering is totally messed up, whenever I add, remove or simply scroll through the tab row (if I'm calling it correctly). The tab row basically disappears and at least 5 seconds to come back, while lots of flashing and buggy behavior. During this time the rendering of the main page is also messed up.
    After it finishes rendering, the main page could still be in a bad state. At which I have to switch tabs or scroll the main page, to force a re-draw of the main page, to get the rendering looking correct.
    The only clue I have is that I have lots and lots of tabs open. And it looks like when I'm on the first few tabs it doesn't happen as badly.. This worked perfectly on 4b8.

    I'm sorry to hear that you have so many issues. What version of Firefox were you using before?
    The double title bar issue has been identified as an issue with the Tax Mix Plus extension but it doesn't affect everyone, it's an interaction with something else (not exactly clear what, although Norton Toolbar was mentioned in one thread).
    There is a new version available that you could try. If Firefox is stable enough to do it...
    orange Firefox button (or Tools menu) > Add-ons > "gear" icon > Check for Updates
    If your beta version won't update, you could try installing [https://addons.mozilla.org/en-us/firefox/addon/tab-mix-plus/ from the add-ons site].
    More generally, could I suggest disabling as many extensions as you can live without for 24 hours, and re-enable them gradually? This should help isolate interactions between them. As you know, you can do that here:
    orange Firefox button (or Tools menu) > Add-ons > Extensions category
    Finally, regarding your old session, if you haven't closed Firefox, you might find a sessionstore.bak file in your profile folder that contains your old session. To easily access that folder, try
    Help > Troubleshooting Information > "Show Folder" button
    Grab a copy of that file and save it somewhere outside the folder because it is overwritten when you close Firefox. Got to run, but if you find one with an appropriate date, someone can help you restore it.

  • Why repaint is automatically called

    in the slot machine program below, you try to run it, play once , after that you leave the bet textfield to be 0, and click play again, when you click down the JOptionMessage dialog, three slot is atomatically set back to lemon, but it shoudn't be that, I didn't call repaint in my program, why
    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    public class Slot extends JFrame implements ActionListener,Runnable
         ImageIcon img;
         JButton play;
         JPanel leftCanvas;
         JPanel centerCanvas;
         JPanel rightCanvas;
         JTextField amount;
         JTextField bet;
         SpinThread t1;
         SpinThread t2;
         SpinThread t3;
         Thread t;
         int credit,betAmount;
         AudioClip audioClip=Applet.newAudioClip(this.getClass().getResource("win.au"));
         public Slot(String s) {
         /** Constructor */
          super( s );
          setSize(300,200);
          img = new ImageIcon("images/lemon.gif") ;
          Container c = getContentPane();
          c.setLayout( new BorderLayout() );
          /** Panel with Label showing title */
         JPanel title = new JPanel ();
          title.setFont(new Font("TimesRoman", Font.BOLD, 16));
          title.add(new Label("Slot Machine Simulation"));
          c.add(title, "North");
          /** Panel with 3 Canvases showing pictures */
          JPanel slotPanel = new JPanel(new GridLayout(1, 3));
          leftCanvas = new JPanel();
          centerCanvas = new JPanel();
          rightCanvas = new JPanel() ;
          slotPanel.add(leftCanvas);
          slotPanel.add(centerCanvas);
          slotPanel.add(rightCanvas) ;
          c.add(slotPanel,"Center") ;
          /** the Bottom panel showing the credit, betting amount and play button */
          JPanel messagePanel = new JPanel(new GridLayout(1,3));
          /** credit panel */
          JPanel creditPanel = new JPanel();
          creditPanel.setLayout(new FlowLayout()) ;
          JLabel label1  = new JLabel("Credit") ;
          creditPanel.add(label1) ;
          amount = new JTextField("1000") ;
          amount.setHorizontalAlignment(JTextField.RIGHT) ;
          amount.setEditable(false) ;
          creditPanel.add(amount) ;
          messagePanel.add(creditPanel) ;     
          /** betting panel*/
          JPanel bettingPanel = new JPanel();
          bettingPanel.setLayout(new FlowLayout()) ;
          JLabel label2  = new JLabel("Bet") ;
          bettingPanel.add(label2) ;
          bet = new JTextField(3) ;
          bet.setText("50") ;
          bet.setHorizontalAlignment(JTextField.RIGHT) ;
          bettingPanel.add(bet) ;
          messagePanel.add(bettingPanel) ;
         /** button panel */
          JPanel buttonPanel = new JPanel();
          buttonPanel.setLayout(new FlowLayout()) ;
          play = new JButton("PLAY") ;
          play.addActionListener(this) ;
          buttonPanel.add(play) ;
          messagePanel.add(buttonPanel) ;
         /** add the last panel to the south end */ 
          c.add(messagePanel,"South") ;
          credit=Integer.parseInt(amount.getText());
          betAmount=Integer.parseInt(bet.getText());
       public void paint(Graphics g)
       {  super.paint(g);
              img.paintIcon(leftCanvas,leftCanvas.getGraphics(),0,0);
          img.paintIcon(centerCanvas,centerCanvas.getGraphics(),0,0);
          img.paintIcon(rightCanvas,rightCanvas.getGraphics(),0,0);
       public void check()
       {credit=Integer.parseInt(amount.getText());
        betAmount=Integer.parseInt(bet.getText());
            if(t1.index==t2.index&&t2.index==t3.index&&t3.index==6)
                 credit=credit+1000000;
                 audioClip.play();
                 //Splash win=new Splash();
                 //win.setSize(200,200);
                 //win.setVisible(true);
        else if(t1.index==t2.index&&t2.index==t3.index)
                credit=credit+betAmount*100;
            else if(t1.index==t2.index||t2.index==t3.index||t3.index==t1.index)
                 credit=credit+betAmount*10;
            else
                 credit=credit-betAmount;
            amount.setText(String.valueOf(credit));
            bet.setText("0");
       public void actionPerformed(ActionEvent e)
            if(e.getSource()==play)
                 credit=Integer.parseInt(amount.getText());
            betAmount=Integer.parseInt(bet.getText());
                 if(betAmount<=0)
                 JOptionPane.showMessageDialog(this,"Bet must be positive!");
           else  if(betAmount>100||betAmount>credit)
                 JOptionPane.showMessageDialog(this,"Bet exceed the upper limit(100) or not enough credit!");
           else if(betAmount<credit&&betAmount<=100&&betAmount>0)
                t1=new SpinThread(leftCanvas,20);
            t2=new SpinThread(centerCanvas,40);
            t3=new SpinThread(rightCanvas,60);
            t=new Thread(this);
             t.setPriority(1);
                t1.start();
                 t2.start();
                 t3.start();
                 t.start();
       public void run()
                boolean done=false;
                while(!done)
                    if(!(t1.isAlive()||t2.isAlive()||t3.isAlive()))
                         done=true;
                check();
       public static void main(String[] args)
             Slot mySlot=new Slot("Slot Machine Simulation");
             mySlot.show();
             mySlot.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    class SpinThread extends Thread
         JPanel p;
         int delay;
         ImageIcon[] img={new ImageIcon("images/ball.gif"),
         new ImageIcon("images/bar.gif"),new ImageIcon("images/bell.gif"),
         new ImageIcon("images/fruit.gif"),new ImageIcon("images/lemeon.gif"),
         new ImageIcon("images/seven.gif")};
         int index;
         public SpinThread(JPanel p,int delay)
              super();
              this.p=p;
              this.delay=delay;
         public void run()
              int i=0;
              while(i<delay)
                   index=Math.round((float)Math.random()*5);
                   display(p.getGraphics());
                   try{
                        sleep(delay);
                   }catch(InterruptedException e){;}
                   i++;
         public void display(Graphics g)
           img[index].paintIcon(p,g,0,0);
    }

    That's the way repaint works
    Anytime a java component which lies beneath some other window is uncovered, the UI thread will do a repaint

  • Firefox opens 4 windows on start

    Every time I open Firefox now, it launches with 4 windows. One is a normal window (showing the site I was on last), and 3 are blank windows with double title bars and an orange Firefox tab. I can't see what's causing this, or how to correct it..?

    You can check:
    * http://kb.mozillazine.org/Preferences_not_saved
    This can be a problem with the file [http://kb.mozillazine.org/sessionstore.js sessionstore.js] and sessionstore.bak in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder]
    Delete [http://kb.mozillazine.org/sessionstore.js sessionstore.js] and sessionstore.bak in the [http://kb.mozillazine.org/Profile_folder_-_Firefox Profile Folder]
    If you see files sessionstore-##.js with a number in the left part of the name like sessionstore-1.js then delete those as well.
    See:
    * http://kb.mozillazine.org/Session_Restore

  • How to detect a signal saturation on voltage channels

    Hi,
    I have many votage channels with personnal's scales.
    I would like to know if it's possible to detect a input saturation (voltage out of  range, +10/-10V for exemple), directly in the acquisition channel.
    I can do reverse scale to know the voltage value but I would like to know if there is a automatic flag in the channel.
    Thinks for your help

    this might work
    import java.awt.*;
    import javax.swing.*;
    import java.awt.event.*;
    class Testing extends JFrame
      public Testing()
        setSize(300,200);
        setLocation(350,200);
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        setUndecorated(true);
        getRootPane().setWindowDecorationStyle(JRootPane.FRAME);
        addMouseListener(new MouseAdapter(){
          public void mousePressed(MouseEvent me){
            if(me.getY() < getContentPane().getY()){
              JOptionPane.showMessageDialog(getContentPane(),"In Title Bar");}}});
        JPanel jp = new JPanel();
        getContentPane().add(jp);
      public static void main(String[] args){new Testing().setVisible(true);}
    }

Maybe you are looking for