I need to use a JPanel as a JButton

We have a requirement here to display a panel full of various text fields and colors, but have it act like a Button. Focus handling, click handling, etc...
Anyone know of a JButton class that lets you use a JPanel as it's content instead of just a text string or icon?

package testthing;
import javax.swing.JFrame;
public class Main {
     * @param args the command line arguments
    public static void main(String[] args) {
        JFrame frame = new NewJFrame();
        frame.setVisible(true);
* NewJFrame.java
* Created on Aug 27, 2010, 12:14:32 PM
package testthing;
import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class NewJFrame extends javax.swing.JFrame {
    /** Creates new form NewJFrame */
    public NewJFrame() {
        initComponents();
        jButton1.setLayout( new GridBagLayout());
        GridBagConstraints gbc = new GridBagConstraints();
        gbc.fill = GridBagConstraints.BOTH;
        gbc.weightx = 1.0;
        gbc.weighty = 1.0;
        jButton1.add(jPanel1, gbc);
    /** 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.
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {
        GridBagConstraints gridBagConstraints;
        jButton1 = new JButton();
        jPanel1 = new JPanel();
        jLabel1 = new JLabel();
        jLabel2 = new JLabel();
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        getContentPane().setLayout(new GridBagLayout());
        jButton1.setContentAreaFilled(false);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        getContentPane().add(jButton1, gridBagConstraints);
        jPanel1.setBackground(new Color(255, 204, 204));
        jPanel1.setLayout(new GridBagLayout());
        jLabel1.setText("jLabel1");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.insets = new Insets(4, 4, 4, 4);
        jPanel1.add(jLabel1, gridBagConstraints);
        jLabel2.setText("jLabel2");
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new Insets(4, 4, 4, 4);
        jPanel1.add(jLabel2, gridBagConstraints);
        gridBagConstraints = new GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.anchor = GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
        getContentPane().add(jPanel1, gridBagConstraints);
        pack();
    }// </editor-fold>
    * @param args the command line arguments
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new NewJFrame().setVisible(true);
    // Variables declaration - do not modify
    private JButton jButton1;
    private JLabel jLabel1;
    private JLabel jLabel2;
    private JPanel jPanel1;
    // End of variables declaration
}

Similar Messages

  • JButton not visible after use of Jpanel removeAll ..

    Hi!
    I'm having a calculator class that inherits JFrame. I need to add more buttons after setting an option from the (view) menu bar .. (from normal to scientific calculator). I needed to use the JPanel removeAll method and then add the normal buttons plus extra buttons. But the problem is, that the Buttons are only visible when I touch them with the mouse.
    Does anybody know why? Thanks for your help!
    See code below (still in construction phase):
    Name: Hemanth. B
    Original code from Website: java-swing-tutorial.html
    Topic : A basic Java Swing Calculator
    Conventions Used in Source code
         1. All JLabel components start with jlb*
         2. All JPanel components start with jpl*
         3. All JMenu components start with jmenu*
         4. All JMenuItem components start with jmenuItem*
         5. All JDialog components start with jdlg*
         6. All JButton components start with jbn*
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class Calculator extends JFrame
    implements ActionListener {
    // Constants
    final int NORMAL = 0;
    final int SCIENTIFIC = 8;
    final int MAX_INPUT_LENGTH = 20;
    final int INPUT_MODE = 0;
    final int RESULT_MODE = 1;
    final int ERROR_MODE = 2;
    // Variables
    int displayMode;
    int calcType = SCIENTIFIC;
    boolean clearOnNextDigit, percent;
    double lastNumber;
    String lastOperator, title;
    private JMenu jmenuFile, jmenuView, jmenuHelp;
    private JMenuItem jmenuitemExit, jmenuitemAbout;
    private JRadioButtonMenuItem jmenuItemNormal = new JRadioButtonMenuItem("Normal");
    private JRadioButtonMenuItem jmenuItemScientific = new JRadioButtonMenuItem("Scientific");
    private     ButtonGroup viewMenuButtonGroup = new ButtonGroup();
    private JLabel jlbOutput;
    private JButton jbnButtons[];
    private JPanel jplButtons, jplMaster, jplBackSpace, jplControl;
    * Font(String name, int style, int size)
    Creates a new Font from the specified name, style and point size.
    Font f12 = new Font("Verdana", 0, 12);
    Font f121 = new Font("Verdana", 1, 12);
    // Constructor
    public Calculator(String title) {
    /* Set Up the JMenuBar.
    * Have Provided All JMenu's with Mnemonics
    * Have Provided some JMenuItem components with Keyboard Accelerators
         //super(title);
         this.title = title;
         //displayCalculator(title);
    }     //End of Contructor Calculator
    private void displayCalculator (String title) {
         //add WindowListener for closing frame and ending program
         addWindowListener (
         new WindowAdapter() {     
         public void windowClosed(WindowEvent e) {
         System.exit(0);
         //setResizable(false);
    //Set frame layout manager
         setBackground(Color.gray);
         validate();
         createMenuBar();
         createMasterPanel();      
         createDisplayPanel();
         clearAll();
         this.getContentPane().validate();
         requestFocus();
         pack();
         //getContentPane().
         setVisible(true);
    private void createMenuBar() {
    jmenuFile = new JMenu("File");
    jmenuFile.setFont(f121);
    jmenuFile.setMnemonic(KeyEvent.VK_F);
    jmenuitemExit = new JMenuItem("Exit");
    jmenuitemExit.setFont(f12);
    jmenuitemExit.setAccelerator(KeyStroke.getKeyStroke( KeyEvent.VK_X,
                                            ActionEvent.CTRL_MASK));
    jmenuFile.add(jmenuitemExit);
    jmenuView = new JMenu("View");
    jmenuFile.setFont(f121);
    jmenuFile.setMnemonic(KeyEvent.VK_W);
    jmenuItemNormal.setMnemonic(KeyEvent.VK_N);
    viewMenuButtonGroup.add(jmenuItemNormal);
    jmenuView.add(jmenuItemNormal);
    jmenuItemScientific.setMnemonic(KeyEvent.VK_S);
    viewMenuButtonGroup.add(jmenuItemScientific);
    jmenuView.add(jmenuItemScientific);
    if (jmenuItemNormal.isSelected() == false &&
    jmenuItemScientific.isSelected() == false)
    jmenuItemScientific.setSelected(true);
         jmenuHelp = new JMenu("Help");
         jmenuHelp.setFont(f121);
         jmenuHelp.setMnemonic(KeyEvent.VK_H);
         jmenuitemAbout = new JMenuItem("About Calculator");
         jmenuitemAbout.setFont(f12);
         jmenuHelp.add(jmenuitemAbout);
         JMenuBar menubar = new JMenuBar();
         menubar.add(jmenuFile);
         menubar.add(jmenuView);
         menubar.add(jmenuHelp);
         setJMenuBar(menubar);
         jmenuItemNormal.addActionListener(this);
         jmenuItemScientific.addActionListener(this);
         jmenuitemAbout.addActionListener(this);
         jmenuitemExit.addActionListener(this);
    private void createDisplayPanel() {
         if (jlbOutput != null) {
         jlbOutput.removeAll();     
         jlbOutput = new JLabel("0",JLabel.RIGHT);
         jlbOutput.setBackground(Color.WHITE);
         jlbOutput.setOpaque(true);
         // Add components to frame
         getContentPane().add(jlbOutput, BorderLayout.NORTH);
         jlbOutput.setVisible(true);
    private void createMasterPanel() {
         if (jplMaster != null) {
         jplMaster.removeAll();     
         jplMaster = new JPanel(new BorderLayout());
         createCalcButtons();      
         jplMaster.add(jplBackSpace, BorderLayout.WEST);
         jplMaster.add(jplControl, BorderLayout.EAST);
         jplMaster.add(jplButtons, BorderLayout.SOUTH);
         ((JPanel)getContentPane()).revalidate();
         // Add components to frame
         getContentPane().add(jplMaster, BorderLayout.SOUTH);
         jplMaster.setVisible(true);
    private void createCalcButtons() {
         int rows = 4;
         int cols = 5 + calcType/rows;
         jbnButtons = new JButton[31];
         // Create numeric Jbuttons
         for (int i=0; i<=9; i++) {
         // set each Jbutton label to the value of index
         jbnButtons[i] = new JButton(String.valueOf(i));
         // Create operator Jbuttons
         jbnButtons[10] = new JButton("+/-");
         jbnButtons[11] = new JButton(".");
         jbnButtons[12] = new JButton("=");
         jbnButtons[13] = new JButton("/");
         jbnButtons[14] = new JButton("*");
         jbnButtons[15] = new JButton("-");
         jbnButtons[16] = new JButton("+");
         jbnButtons[17] = new JButton("sqrt");
         jbnButtons[18] = new JButton("1/x");
         jbnButtons[19] = new JButton("%");
         jplBackSpace = new JPanel();
         jplBackSpace.setLayout(new GridLayout(1, 1, 2, 2));
         jbnButtons[20] = new JButton("Backspace");
         jplBackSpace.add(jbnButtons[20]);
         jplControl = new JPanel();
         jplControl.setLayout(new GridLayout(1, 2, 2 ,2));
         jbnButtons[21] = new JButton(" CE ");
         jbnButtons[22] = new JButton("C");
         jplControl.add(jbnButtons[21]);
         jplControl.add(jbnButtons[22]);
         //if (calcType == SCIENTIFIC) {     
         jbnButtons[23] = new JButton("s");
         jbnButtons[24] = new JButton("t");
         jbnButtons[25] = new JButton("u");
         jbnButtons[26] = new JButton("v");
         jbnButtons[27] = new JButton("w");
         jbnButtons[28] = new JButton("x");
         jbnButtons[29] = new JButton("y");
         jbnButtons[30] = new JButton("z");
    // Setting all Numbered JButton's to Blue. The rest to Red
         for (int i=0; i<jbnButtons.length; i++)     {
         //activate ActionListener
         System.out.println("add action listener: " + i);
         jbnButtons.addActionListener(this);
         //set button text font/colour
         jbnButtons[i].setFont(f12);
         jbnButtons[i].invalidate();
         if (i<10)
              jbnButtons[i].setForeground(Color.blue);               
         else
              jbnButtons[i].setForeground(Color.red);
         // container for Jbuttons
         jplButtons = new JPanel(new GridLayout(rows, cols, 2, 2));
    System.out.println("Cols: " + cols);      
         //Add buttons to keypad panel starting at top left
         // First row
         // extra left buttons for scientific
         if (calcType == SCIENTIFIC) {
         System.out.println("Adding Scientific buttons");
         setSize(400, 217);
         setLocation(200, 250);
         jplButtons.add(jbnButtons[23]);
         jplButtons.add(jbnButtons[27]);
         } else {
         setSize(241, 217);
         setLocation(200, 250);
         for(int i=7; i<=9; i++)          {
         jplButtons.add(jbnButtons[i]);
         // add button / and sqrt
         jplButtons.add(jbnButtons[13]);
         jplButtons.add(jbnButtons[17]);
         // Second row
         // extra left buttons for scientific
         if (calcType == SCIENTIFIC) {
         System.out.println("Adding Scientific buttons");
         jplButtons.add(jbnButtons[24]);
         jplButtons.add(jbnButtons[28]);
         for(int i=4; i<=6; i++)     {
         jplButtons.add(jbnButtons[i]);
         // add button * and x^2
         jplButtons.add(jbnButtons[14]);
         jplButtons.add(jbnButtons[18]);
         // Third row
         // extra left buttons for scientific
         if (calcType == SCIENTIFIC) {
         System.out.println("Adding Scientific buttons");
         jplButtons.add(jbnButtons[25]);
         jplButtons.add(jbnButtons[29]);
         for( int i=1; i<=3; i++) {
         jplButtons.add(jbnButtons[i]);
         //adds button - and %
         jplButtons.add(jbnButtons[15]);
         jplButtons.add(jbnButtons[19]);
         //Fourth Row
         // extra left buttons for scientific
         if (calcType == SCIENTIFIC) {
         System.out.println("Adding Scientific buttons");
         jplButtons.add(jbnButtons[26]);
         jplButtons.add(jbnButtons[30]);
         // add 0, +/-, ., +, and =
         jplButtons.add(jbnButtons[0]);
         jplButtons.add(jbnButtons[10]);
         jplButtons.add(jbnButtons[11]);
         jplButtons.add(jbnButtons[16]);
         jplButtons.add(jbnButtons[12]);
         jplButtons.revalidate();
    // Perform action
    public void actionPerformed(ActionEvent e){
         double result = 0;
         if(e.getSource() == jmenuitemAbout) {
         //JDialog dlgAbout = new CustomABOUTDialog(this,
         //                              "About Java Swing Calculator", true);
         //dlgAbout.setVisible(true);
         } else if(e.getSource() == jmenuitemExit) {
         System.exit(0);
    if (e.getSource() == jmenuItemNormal) {
    calcType = NORMAL;
    displayCalculator(title);
    if (e.getSource() == jmenuItemScientific) {
    calcType = SCIENTIFIC;
    displayCalculator(title);
    System.out.println("Calculator is set to "
    + (calcType == NORMAL?"Normal":"Scientific") + " :" + jbnButtons.length);      
         // Search for the button pressed until end of array or key found
         for (int i=0; i<jbnButtons.length; i++)     {
         if(e.getSource() == jbnButtons[i]) {
              System.out.println(i);
              switch(i) {
              case 0:
                   addDigitToDisplay(i);
                   break;
              case 1:
                   System.out.println("1");
                   addDigitToDisplay(i);
                   break;
              case 2:
                   addDigitToDisplay(i);
                   break;
              case 3:
                   addDigitToDisplay(i);
                   break;
              case 4:
                   addDigitToDisplay(i);
                   break;
              case 5:
                   addDigitToDisplay(i);
                   break;
              case 6:
                   addDigitToDisplay(i);
                   break;
              case 7:
                   addDigitToDisplay(i);
                   break;
              case 8:
                   addDigitToDisplay(i);
                   break;
              case 9:
                   addDigitToDisplay(i);
                   break;
              case 10:     // +/-
                   processSignChange();
                   break;
              case 11:     // decimal point
                   addDecimalPoint();
                   break;
              case 12:     // =
                   processEquals();
                   break;
              case 13:     // divide
                   processOperator("/");
                   break;
              case 14:     // *
                   processOperator("*");
                   break;
              case 15:     // -
                   processOperator("-");
                   break;
              case 16:     // +
                   processOperator("+");
                   break;
              case 17:     // sqrt
                   if (displayMode != ERROR_MODE) {
                   try {
                        if (getDisplayString().indexOf("-") == 0)
                        displayError("Invalid input for function!");
                        result = Math.sqrt(getNumberInDisplay());
                        displayResult(result);
                   catch(Exception ex) {
                        displayError("Invalid input for function!");
                        displayMode = ERROR_MODE;
                   break;
              case 18:     // 1/x
                   if (displayMode != ERROR_MODE){
                   try {
                        if (getNumberInDisplay() == 0)
                        displayError("Cannot divide by zero!");
                        result = 1 / getNumberInDisplay();
                        displayResult(result);
                   catch(Exception ex) {
                        displayError("Cannot divide by zero!");
                        displayMode = ERROR_MODE;
                   break;
              case 19:     // %
                   if (displayMode != ERROR_MODE){
                   try {
                        result = getNumberInDisplay() / 100;
                        displayResult(result);
                   catch(Exception ex) {
                        displayError("Invalid input for function!");
                        displayMode = ERROR_MODE;
                   break;
              case 20:     // backspace
                   if (displayMode != ERROR_MODE) {
                   setDisplayString(getDisplayString().substring(0,
                   getDisplayString().length() - 1));
                   if (getDisplayString().length() < 1)
                        setDisplayString("0");
                   break;
              case 21:     // CE
                   clearExisting();
                   break;
              case 22:     // C
                   clearAll();
                   break;
    void setDisplayString(String s) {
         jlbOutput.setText(s);
    String getDisplayString () {
         return jlbOutput.getText();
    void addDigitToDisplay(int digit) {
         if (clearOnNextDigit)
         setDisplayString("");
         String inputString = getDisplayString();
         if (inputString.indexOf("0") == 0) {
         inputString = inputString.substring(1);
         if ((!inputString.equals("0") || digit > 0)
                             && inputString.length() < MAX_INPUT_LENGTH) {
         setDisplayString(inputString + digit);
         displayMode = INPUT_MODE;
         clearOnNextDigit = false;
    void addDecimalPoint() {
         displayMode = INPUT_MODE;
         if (clearOnNextDigit)
         setDisplayString("");
         String inputString = getDisplayString();
         // If the input string already contains a decimal point, don't
         // do anything to it.
         if (inputString.indexOf(".") < 0)
         setDisplayString(new String(inputString + "."));
    void processSignChange() {
         if (displayMode == INPUT_MODE) {
         String input = getDisplayString();
         if (input.length() > 0 && !input.equals("0"))     {
              if (input.indexOf("-") == 0)
              setDisplayString(input.substring(1));
              else
              setDisplayString("-" + input);
         } else if (displayMode == RESULT_MODE) {
         double numberInDisplay = getNumberInDisplay();
         if (numberInDisplay != 0)
         displayResult(-numberInDisplay);
    void clearAll() {
         setDisplayString("0");
         lastOperator = "0";
         lastNumber = 0;
         displayMode = INPUT_MODE;
         clearOnNextDigit = true;
    void clearExisting() {
         setDisplayString("0");
         clearOnNextDigit = true;
         displayMode = INPUT_MODE;
    double getNumberInDisplay()     {
         String input = jlbOutput.getText();
         return Double.parseDouble(input);
    void processOperator(String op) {
         if (displayMode != ERROR_MODE) {
         double numberInDisplay = getNumberInDisplay();
         if (!lastOperator.equals("0")) {
              try {
              double result = processLastOperator();
              displayResult(result);
              lastNumber = result;
              catch (DivideByZeroException e)     {
              displayError("Cannot divide by zero!");
         } else {
         lastNumber = numberInDisplay;
         clearOnNextDigit = true;
         lastOperator = op;
    void processEquals() {
         double result = 0;
         if (displayMode != ERROR_MODE){
         try {
              result = processLastOperator();
              displayResult(result);
         catch (DivideByZeroException e) {
              displayError("Cannot divide by zero!");
         lastOperator = "0";
    double processLastOperator() throws DivideByZeroException {
         double result = 0;
         double numberInDisplay = getNumberInDisplay();
         if (lastOperator.equals("/")) {
         if (numberInDisplay == 0)
              throw (new DivideByZeroException());
         result = lastNumber / numberInDisplay;
         if (lastOperator.equals("*"))
         result = lastNumber * numberInDisplay;
         if (lastOperator.equals("-"))
         result = lastNumber - numberInDisplay;
         if (lastOperator.equals("+"))
         result = lastNumber + numberInDisplay;
         return result;
    void displayResult(double result){
         setDisplayString(Double.toString(result));
         lastNumber = result;
         displayMode = RESULT_MODE;
         clearOnNextDigit = true;
    void displayError(String errorMessage){
         setDisplayString(errorMessage);
         lastNumber = 0;
         displayMode = ERROR_MODE;
         clearOnNextDigit = true;
    public static void main(String args[]) {
         Calculator calci = new Calculator("My Calculator");
         calci.displayCalculator("My Calculator");
    System.out.println("Exitting...");
    }     //End of Swing Calculator Class.
    class DivideByZeroException extends Exception{
    public DivideByZeroException() {
         super();
    public DivideByZeroException(String s) {
         super(s);
    class CustomABOUTDialog extends JDialog implements ActionListener {
    JButton jbnOk;
    CustomABOUTDialog(JFrame parent, String title, boolean modal){
         super(parent, title, modal);
         setBackground(Color.black);
         JPanel p1 = new JPanel(new FlowLayout(FlowLayout.CENTER));
         StringBuffer text = new StringBuffer();
         text.append("Calculator Information\n\n");
         text.append("Developer:     Hemanth\n");
         text.append("Version:     1.0");
         JTextArea jtAreaAbout = new JTextArea(5, 21);
         jtAreaAbout.setText(text.toString());
         jtAreaAbout.setFont(new Font("Times New Roman", 1, 13));
         jtAreaAbout.setEditable(false);
         p1.add(jtAreaAbout);
         p1.setBackground(Color.red);
         getContentPane().add(p1, BorderLayout.CENTER);
         JPanel p2 = new JPanel(new FlowLayout(FlowLayout.CENTER));
         jbnOk = new JButton(" OK ");
         jbnOk.addActionListener(this);
         p2.add(jbnOk);
         getContentPane().add(p2, BorderLayout.SOUTH);
         setLocation(408, 270);
         setResizable(false);
         addWindowListener(new WindowAdapter() {
              public void windowClosing(WindowEvent e) {
                   Window aboutDialog = e.getWindow();
                   aboutDialog.dispose();
         pack();
    public void actionPerformed(ActionEvent e) {
         if(e.getSource() == jbnOk) {
         this.dispose();
    Message was edited by:
    dungorg

    Swing related questions should be posted in the Swing forum.
    After adding or removing components from a visible panel you need to use panel.revalidate() and sometimes panel.repaint();
    If you need further help then you need to create a [url http://homepage1.nifty.com/algafield/sscce.html]Short, Self Contained, Compilable and Executable, Example Program (SSCCE) that demonstrates the incorrect behaviour, because I can't guess exactly what you are doing based on the information provided.
    Don't forget to use the [url http://forum.java.sun.com/help.jspa?sec=formatting]Code Formatting Tags so the posted code retains its original formatting.

  • What component Should I use?, Jpanel doesn't work

    Hi
    I need a program that has a window that can go fullscreen and windowed (I did that with a Jframe in fullscreen mode with a jpnale and a 800x600 Jpanel and destroying them with an object that maneges them), I did it with a jframe that contained a Jpanel, I used a Jpanel to avoid the flickering on the screen but I also need to change the font type and the font size, but the setFont on the Jpanel doesn't change the font (as I have realized and also read here [http://forum.java.sun.com/thread.jspa?forumID=257&threadID=150588] ), so I'm lost, I might have to redo the whole thing, but I just wanted to know what component should I use for a window that is going to have custom graphics and need diffrent fonts and diffrent font sizes and work in fullscreen without flickering
    Thank you for your attention, I would aprecciate any help given

    for example:
    import java.awt.BorderLayout;
    import java.awt.Dimension;
    import java.awt.Font;
    import java.awt.Graphics;
    import java.awt.Graphics2D;
    import java.awt.RenderingHints;
    import javax.swing.JFrame;
    import javax.swing.JPanel;
    import javax.swing.JSlider;
    import javax.swing.event.ChangeEvent;
    import javax.swing.event.ChangeListener;
    public class JPanelFont extends JPanel
      private Font font = getFont();
      private String myString = "Fubars Rule";
      private int fontSize = font.getSize();
      private JSlider slider = new JSlider(0, 100, fontSize);
      public JPanelFont()
        setPreferredSize(new Dimension(620, 250));
        setLayout(new BorderLayout());
        JPanel inputPanel = createInputPanel();
        add(inputPanel, BorderLayout.SOUTH);
      private JPanel createInputPanel()
        JPanel ip = new JPanel();
        slider.setMajorTickSpacing(20);
        slider.setMinorTickSpacing(5);
        slider.setPaintTicks(true);
        slider.setPaintLabels(true);
        ip.add(slider);
        slider.addChangeListener(new ChangeListener()
          public void stateChanged(ChangeEvent evt)
            fontSize = (Integer)slider.getValue();
            repaint();
        return ip;
      @Override
      protected void paintComponent(Graphics g)
        Graphics2D g2 = (Graphics2D)g;
        Object originalHint = g2.getRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
        super.paintComponent(g2);
        myPaint(g2);
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, originalHint);
      private void myPaint(Graphics2D g2)
        font = font.deriveFont(Font.BOLD, fontSize);
        g2.setFont(font);
        g2.drawString(myString, 20, 100);
      private static void createAndShowUI()
        JFrame frame = new JFrame("Dynamic JPanel Font");
        frame.getContentPane().add(new JPanelFont());
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.pack();
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
      public static void main(String[] args)
        java.awt.EventQueue.invokeLater(new Runnable()
          public void run()
            createAndShowUI();
    }Edited by: Encephalopathic on May 21, 2008 9:18 PM

  • I have a new mac book pro which i use in england but I need to use German charachters frequently, is there a way of having both visable on the keyboard?

    I have a new mac book pro which i use in england but I need to use German charachters frequently, is there a way of having both visable on the keyboard?
    For example so that I can just press shift or another key to get the German character.

    Some may already exist, but you will have to learn them.  On my old system these can be found through keyviewer.app  For example, if I press option+s I get ß   Umlaut is a bit cumbersome as option+u then the actual letter.  It may be possible to bind a key to do this function, possibly through System Preferences > Keyboard > Shortcuts
    I have old, old references for utilities that let you rebind keys to other functions, and you would have to see if they have modern equivalents.
    Ukelele Mac OS X Keyboard Layout Editor - http://scripts.sil.org/cms/scripts/page.php?site_id=nrsi&id=ukelele - mostly useful for character, not function mapping.
    Check Butler, ikeys, quickeys or Spark

  • HT3275 I need to use a Western Digital external drive on both my Mac and a PC.  To do this I need to format the drive in FAT 32.  However, Time Machine won't recognize this format.  Is there a work-around?

    I need to use my external drive on my Mac and a PC, so I formatted it in FAT 32.  I found that Time Machine doesn't recognize this format and cannot back up to it.  So, if I want to use Time Machine I need to go back to a Mac format.  Is there any way to get Time Machine to save onto a FAT 32 formatted drive?

    It's usually not a good idea to use a Time Machine drive for anything else. It's too easy to make mistakes, or not do regular backups, or run out of space.  See Time Machine - Frequently Asked Questions #1 and 3.
    But you can create a second partition on the drive, for use with Windoze.
    See #5 in the FAQ for formatting instructions.  You'll need to select 2 partitions.  It's usually best to put the Time Machine partition first, and it should have the Mac OS Extended (Journaled) Format.  Make the second one MS-DOS (FAT), although you might prefer ExFAT.
    Be sure to specify the GUID Partition table.

  • I phone 5 need to use antivirus? If i need to use antivirus which is best app for i phone 5

    I phone 5 need to use any antivirus ? If i want to use which is the best app for i phone 5

    It is certainly not a virus. There are none.
    Try the basic troubleshooting steps.
    Start here: http://www.apple.com/support/iphone/assistant/phone/#section_1
    Sometimes all that is required is to restart the iPhone.
    The final step is to restore it. Always back up your iPhone first.

  • IPhone 5s with hearing aids via Bluetooth. Need to use the phone for voice, what's the best distance that the mic will pick up your voice

    I wear hearing aids that are made for Apple, the audio will go into the hearing aids via Bluetooth. I'll need to use my phone for voice only.. I drive for work and have a wok oh one too and both are synced to a bluetooh headset (LG). I'm trying to figure out how to talk on both phones ( use speakerphone on work phone?) without using a bluretooh headset.  I don't know the range of the microphone on the IPHON, thinking about hanging it around my neck or put the phone into a stand/holder on the dash and use the speakerphone feature.  Looking for ideas to make this simple

    You can't do anything with that problem.
    Take your iPhone to the closest Apple Store and they will give you new one for 200€/$ or if you bought your iPhone in less than 12 months you will get it for free.

  • How do I go back to Firefox 5.0? I need to use Selenium IDE, which is not yet compatible with 6.0.

    How do I go back to Firefox 5.0? I need to use Selenium IDE, which is not yet compatible with 6.0.

    The link is to the latest update to 4.o which was 4.0.1
    The 4.0.1 and 5.0 are two separate versions as installing 4.0.1 over 5.0 will just give you the old 4.0.1 as the end result.
    The 5.0 is partially as a security update in place of 4.0.2.
    The Skype extension was only for to make it so you can dial phone numbers on a web page in the separate Skype program right so if you were not using it then no need for the Skype extension for the separate Skype application to work.

  • How to connect an apple tv to an enterprise network with a username and a password?   I need to use it over my university's wifi. theres no option to enter username and password. how to connect the apple tv to such enterprise network?

    How to connect an apple tv to an enterprise network with a username and a password?
    I need to use it over my university's wifi. theres no option to enter username and password. how to connect the apple tv to such enterprise network?

    Contact the University's IT dept, they may be able to set something up on the network to allow the ATV to connect without the need for a user name/password.

  • My IPAD2 has now a little box around everything I tap.  I have tried to reset it .It is not working the same thing occurs.  I have it plugged inTo my MAC OSX and trying to back up but i am told i need to use passcode. Well I cannot get into my IPAD now.

    My IPAD has a little box around everything I tap.  I have tried to reset the IPAD 2 but to no avail.  Now I am locked out and cannot put my passcode into the Ipad2 so I cannot back up the IPAD 2 when plugged in.  It is charged ..I was reading a Foot Smart email when this occured. Help

    Sounds like you have VoiceOver (one of the accessibility features) 'on'. Try triple-clicking the home button and see if that turns it off, and if it does you can then change what a triple-click does via Settings > General > Accessibility > Accessibility Shortcut (or Triple-Click Home depending upon the iOS version).
    If that doesn't turn it off then you can either turn it off directly on the iPad (you need to use a tap-to-select and then double-tap to activate/type process and 3 fingered scrolling) to go into Settings > General > Accessibility and turn VoiceOver 'off', or you can do it by connecting to your computer's iTunes (after typing in your passcode via the tap/double-tap process) : http://support.apple.com/kb/HT4064

  • HT1386 I recently updated and restored my Iphone on a Mac. My music was erased, therefore, I am trying to sync all of the music from my computer into the iPhone, but it says that I need to use the original computer/itunes in order to sync, but it is the s

    I recently updated and restored my Iphone on a Mac. My music was erased, therefore, I am trying to sync all of the music from my computer into the iPhone, but it says that I need to use the original computer/itunes in order to sync, but it is the same computer and iTunes account. The error reads: The iPhone, "Name" is synced with another iTunes library. Do you want to erase this iPhone and a sync with this iTunes library? If I click "Erase and Sync," will it delete my contacts, apps, etc?

    The following may help: iOS: Device not recognized in iTunes for Windows

  • How can I get the 23 July update to load onto my iPad. I haven't been able to access my documents or work for weeks and need to use it. Has anyone else had similar problems?

    How can I get the 23 July update to load onto my iPad. I haven't been able to access my documents or work for weeks and need to use it. Has anyone else had similar problems?

    Hello Arthur,
    Thank you for the reply.
    You were correct that deleting the app and reinstalling it was the only thing to make it work but unfortunately I lost all the documents I made, even though they were backed up to iCloud before i deleted the app. At the same time as deleting pages I had to delete keynote and numbers too, so I've lost all the documents in them too.
    The mb of data which was assigned to each programme in iCloud has reduced, so. I guess they are gone for good. Is there any other way to reaccess them?
    Not your fault but I am a bit fed up the the iPad. I have lost work that I've done and have no other copy apart from what was in iCloud, as I don't have a printer and couldn't email them too myself as I couldn't get into the programme and  i've also got episodes of tv series I purchased that I can't download and albums that are half downloaded with songs missing, so I feel a bit swindled out of time and money and am going back to DVD ,  pen and paper and CDs .
    Instead of using iCloud I guess the only way to make sure I don't loose any more documents it to email them to myself each time I save them on the iPad. Is there anything else you could suggest please?
    I don't have any other apple products apart from iPods, so I can't access the iCloud on anything else can I?
    Thanks
    Amanda

  • Print a file to printer wirelessly and without need to use CD drive to install driver?

    I have a HP-P1006 printer in my conference room and sometimes my guest want to send print to my printer and I have to connect their laptop with USB cable to my printer and install printer driver thought CD Drive. I want to know if there is a way to print a file to printer wirelessly and without need to use CD drive to install driver? (I don't have a wireless network in my conference room) 

    Is it possible to automate Adobe Reader to load files, then set the staple property and location, then print them out? I've seen in .NET 3.0 that there is a Enumeration for Stapling in the System.Printing Namespace. I need to figure out how to automate the printing in adobe but right before it prints, have .NET assign the printer and whether it should be stapled or not.

  • HT204074 So a family needs to use the same apple id accross all devices?

    If I am understanding this correctly, a family used computer with different log ids will have to use the same apple id.  Is this correct?

    Welcome to the Apple community.
    Only one of your libraries needs to use your iTunes Store Apple ID for home sharing. Your other computers can use their own ID for iTunes, so long as they use the same ID as all of the devices on the network for home sharing.

  • Do you need to use an email as an apple ID?    We have a family email which is currently the apple ID so I can keep track of purchases but i have 2 iPhones and 2 itouches. Can all 4 devices have different apple ID under the same email address. Also for th

    Do you need to use an email as an apple ID?    We have a family email which is currently the apple ID so I can keep track of purchases but i have 2 iPhones and 2 itouches. Can all 4 devices have different apple ID under the same email address. Also I wanted to know because for the game center we wanted to keep track of each individual not just o e account.  DID I MAKE SENSE

    Figured it out. Thanks.

Maybe you are looking for

  • Sharing games with different user accounts

    Hello. I've been meaning to ask this for ages and was hoping for some help. There are four user accounts on my mac and my son and daughter love Zoo Tycoon. My question is, how do I share the actual app between the accounts as I can't seem to sort out

  • Can you use a gift card (other then an iTunes gift card) to buy music?

    I've been trying to figure out if i can use my American Express Gift Card to buy music on iTunes and im starting to think i can't. Anyone know if i can? Or how to do that (if so)? Windows XP

  • Question on creation of t-code for SAP query

    Hello, I posted a thread in here back on 06/20/2007 asking for help on creating a t-code for a SAP query. one of the responses that I recieved was <i>"Sure, all you need to do is get the report name which is generated by the query. You can find this

  • Update to 2.0.2

    I saw on Apple's page that 2.0.2 was available, so I plugged my phone in and hit update. iTunes told me that 2.0.1 was the latest version. I thought this was odd so I clicked it again: the same message. I double checked the page to see if I had the f

  • [xmonad] uniquely addressing each ppVisible workspace

    Hi everyone. I'm having some troubles getting a certain piece of my xmonad configuration working. My Haskell skills are not up to par just yet; therefore reading documentation does not necessarily translate to the capability of solving the problem at