java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
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.*;
public class InputFilePanel
extends JPanel
{
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 ( ) ;
}
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." ) ;
}
}
public void load ( String filename )
{
txFilename.setText ( filename ) ;
load ( ) ;
}
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." ) ;
}
}
private class FileLoader
implements ActionListener
{
public void actionPerformed ( ActionEvent ev ) { load ( ) ; }
}
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 ( ) ;
}