KickJava   Java API By Example, From Geeks To Geeks.

Java > Java SE, EE, ME > javax > swing > JPanel

javax.swing
Class JPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible
Direct Known Subclasses:
AbstractColorChooserPanel, JSpinner.DefaultEditor
See Also:
Top Examples, Source Code, XMLEncoder

public AccessibleContext getAccessibleContext()
See Also:
JComponent, Accessible
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public PanelUI getUI()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public String getUIClassID()
See Also:
UIDefaults.getUI(javax.swing.JComponent), JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JPanel()
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JPanel(boolean isDoubleBuffered)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JPanel(LayoutManager layout)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public JPanel(LayoutManager layout,
              boolean isDoubleBuffered)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1598]A panel with BorderLayout
By Anonymous on 2005/11/04 20:23:08  Rate
JPanel mainPanel = new JPanel  (  ) ; 
 mainPanel.setLayout  ( new BorderLayout  ( 4, 4 )  ) ; 
 mainPanel.add  ( BorderLayout.NORTH,new JLabel  ( "Kick Java" )  ) ; 
 


protected String paramString()
See Also:
JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void setUI(PanelUI ui)
See Also:
UIDefaults.getUI(javax.swing.JComponent)
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


public void updateUI()
See Also:
JComponent
Geek's Notes:
Description  Add your codes or notes  Search More Java Examples  


[1609]JFC panel that provides an input field for a filename and shows the file contents -- not editable
By Anonymous on 2005/11/04 20:23:08  Rate
import java.awt.*; 
 import java.awt.event.*; 
 import javax.swing.*; 
 import java.io.*; 
  
  
 /** 
 JFC panel that provides an input field for a filename and shows the file 
 contents -- not editable. 
 */
 
 public class InputFilePanel 
     extends JPanel 
  {  
     /** 
     Constructor lays out the GUI and attach event handlers to load and save 
     the target file. 
     */
 
     public InputFilePanel  (  )  
      {  
         setLayout  ( new BorderLayout  ( 4, 4 )  ) ; 
  
  
         JPanel pnFilename = new JPanel  (  ) ; 
         pnFilename.setLayout  ( new FlowLayout  ( FlowLayout.LEFT )  ) ; 
         pnFilename.add  ( lblFilename ) ; 
         pnFilename.add  ( txFilename ) ; 
         pnFilename.add  ( ckUpdate ) ; 
         pnFilename.add  ( bnSave ) ; 
  
  
         JPanel pnContent = new JPanel  (  ) ; 
         pnContent.setLayout  ( new BorderLayout  ( 4, 4 )  ) ; 
         pnContent.add  ( BorderLayout.NORTH, lblContent ) ; 
         pnContent.add  ( BorderLayout.CENTER, new JScrollPane  ( txContent )  ) ; 
  
  
         add  ( BorderLayout.NORTH, pnFilename ) ; 
         add  ( BorderLayout.CENTER, pnContent ) ; 
  
  
         txFilename.addActionListener  ( new FileLoader  (  )  ) ; 
         bnSave.addActionListener  ( new FileSaver  (  )  ) ; 
  
  
         txContent.setFont  ( new Font  ( "Courier New", Font.PLAIN, 14 )  ) ; 
  
  
         txFilename.setToolTipText  ( "Hit ENTER to load the filename you've typed" ) ; 
         ckUpdate.setToolTipText  ( "Check this box to automatically reload the file before running a transform" ) ; 
         bnSave.setToolTipText  ( "Save the file -- overwrites any changes from an external editor" ) ; 
      }  
  
  
     public String getContent  (  )  
      {  
         if  ( ckUpdate.isSelected  (  )  )  
             load  (  ) ; 
  
  
         return txContent.getText  (  ) ; 
      }  
  
  
     /** 
     Loads the file named in  { @link #txFilename }  into  { @link #txContent } . 
     */
 
     public void load  (  )  
      {  
         try 
          {  
             InputStream in = new FileInputStream  ( txFilename.getText  (  )  ) ; 
             int c = -1; 
             StringBuffer buffer = new StringBuffer  (  ) ; 
             while  (  ( c = in.read  (  )  )  != -1 )  
                 buffer.append  (  ( char )  c ) ; 
  
  
             txContent.setText  ( buffer.toString  (  )  ) ; 
  
  
             in.close  (  ) ; 
          }  
         catch  ( IOException ex )  
          {  
             System.out.println  ( "Couldn't load file." ) ; 
          }  
      }  
  
  
     /** 
     Sets the passed filename into  { @link #txFilename }  and delegates to 
      { @link #load (  )  load } . 
     */
 
     public void load  ( String filename )  
      {  
         txFilename.setText  ( filename ) ; 
         load  (  ) ; 
      }  
  
  
     /** 
     Saves the contents of  { @link #txContent }   ( back )  to the file named 
     by  { @link #txFilename } . 
     */
 
     public void save  (  )  
      {  
         try 
          {  
             OutputStream out = new FileOutputStream  ( txFilename.getText  (  )  ) ; 
             String content = txContent.getText  (  ) ; 
             for  ( int c = 0; c  <  content.length  (  ) ; ++c )  
                 out.write  (  ( char )  content.charAt  ( c )  ) ; 
             out.close  (  ) ; 
          }  
         catch  ( IOException ex )  
          {  
             System.out.println  ( "Couldn't save file." ) ; 
          }  
      }  
  
  
     /** 
     Event handler for  { @link #txFilename }  -- delegates to 
      { @link load (  )  load } . 
     */
 
     private class FileLoader 
         implements ActionListener 
      {  
         public void actionPerformed  ( ActionEvent ev )   {  load  (  ) ;  }  
      }  
  
  
     /** 
     Event handler for  { @link #bnSave }  -- delegates to 
      { @link save save } . 
     */
 
     private class FileSaver 
         implements ActionListener 
      {  
         public void actionPerformed  ( ActionEvent ev )   {  save  (  ) ;  }  
      }  
  
  
     private JLabel lblFilename = new JLabel  ( "Filename:" ) ; 
     private JTextField txFilename = new JTextField  ( 18 ) ; 
     private JCheckBox ckUpdate = new JCheckBox  ( "Auto-update on transform" ) ; 
     private JButton bnSave = new JButton  ( "Save" ) ; 
  
  
     private JLabel lblContent = new JLabel  ( "Content:" ) ; 
     private JTextArea txContent = new JTextArea  (  ) ; 
  }  
  
  
 

Popular Tags