*
javax.swing.UIManager
.getSystemLookAndFeelClassName() // static
.getCrossPlatformLookAndFeelClassName() // static
.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel") // static
"swing.defaultlaf"
javax.swing.SwingUtilities
.updateComponentTreeUI() // static
* 이벤트 리스너
java.awt.event.ActionEvent -> java.awt.AWTEvent
.getActionCommand() // 문자열
java.awt.event.ComponentEvent -> java.awt.AWTEvent
java.awt.event.InputEvent -> java.awt.event.ComponentEvent
java.awt.event.MouseEvent -> java.awt.event.InputEvent
.isPopupTrigger()
mousePressed, mouseReleased 두 곳 모두에서 체크해야 된다
.getClickCount()
java.awt.event.ActionListener // interface
void actionPerformed(ActionEvent e);
java.awt.event.MouseAdapter
void mouseClicked(MouseEvent e)
*
javax.swing.tree.TreeModel // interface
Object getRoot();
Object getChild(Object parent, int index);
int getChildCount(Object parent);
boolean isLeaf(Object node);
void valueForPathChanged(TreePath path, Object newValue);
int getIndexOfChild(Object parent, Object child);
addTreeModelListener(TreeModelListener l);
removeTreeModelListener(TreeModelListener l);
javax.swing.tree.TreePath
javax.swing.tree.DefaultMutableTreeNode
.getPath()
javax.swing.table.AbstractTableModel // TableModel
int getColumnCount()
int getRowCount()
Object getValueAt(int rowIndex, int columnIndex)
String getColumnName(int columnIndex)
boolean isCellEditable(int rowIndex, int columnIndex)
void setValueAt(Object aValue, int rowIndex, int columnIndex)
*
java.awt.BorderLayout
java.awt.Component
.addMouseListener()
java.awt.Container -> java.awt.Component
.setLayout()
java.awt.Window -> java.awt.Container
java.awt.Frame -> java.awt.Window
javax.swing.JFrame -> java.awt.Frame
.getContentPane() // java.awt.Container
javax.swing.JComponent -> java.awt.Container
.setBackground()
.setBorder()
javax.swing.JPanel -> javax.swing.JComponent
javax.swing.JScrollPane -> javax.swing.JComponent
javax.swing.AbstractButton -> javax.swing.JComponent
.setActionCommand()
.setText()
javax.swing.JLabel -> javax.swing.JComponent
.setText()
javax.swing.text.JTextComponent -> javax.swing.JComponent
.setText()
.replaceSelection()
javax.swing.JTextArea -> javax.swing.text.JTextComponent
javax.swing.JEditorPane -> javax.swing.text.JTextComponent
javax.swing.JButton -> javax.swing.AbstractButton
javax.swing.JCheckBox -> javax.swing.JToggleButton
javax.swing.ButtonGroup
javax.swing.JRadioButton -> javax.swing.JToggleButton
javax.swing.JProgressBar -> javax.swing.JComponent
.setValue()
javax.swing.JSlider -> javax.swing.JComponent
javax.swing.DefaultListModel -> javax.swing.AbstractListModel // DefaultListModel<>
.addElement()
javax.swing.JList -> javax.swing.JComponent
.setListData()
.setSelectedIndex()
.getModel()
javax.swing.JTree -> javax.swing.JComponent
.setModel()
.expandPath()
javax.swing.JTable -> javax.swing.JComponent
import java.awt.*;
import javax.swing.*;
public class SwingTest04{
static class JFrameTest extends JFrame{
public JFrameTest(){
JCheckBox ch01, ch02;
JRadioButton rb01, rb02;
Panel p01, p02;
ch01=new JCheckBox("..", true);
ch02=new JCheckBox("..", false);
rb01=new JRadioButton("..", true);
rb02=new JRadioButton("..", false);
p01=new Panel();
p01.add(ch01);
p01.add(ch02);
getContentPane().add(p01, "North");
ButtonGroup gr01 = new ButtonGroup();
gr01.add(rb01);
gr01.add(rb02);
p02=new Panel();
p02.add(rb01);
p02.add(rb02);
getContentPane().add(p02, "Center");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(300, 150);
setVisible(true);
}
}
public static void main(String[] args){
new JFrameTest( );
}
}
import javax.swing.*;
import javax.swing.event.*;
import javax.swing.tree.*;
import java.io.File;
public class FileTreeDemo {
static class FileTreeModel implements TreeModel {
protected File root;
public FileTreeModel(File root) { this.root = root; }
public Object getRoot() { return root; }
public boolean isLeaf(Object node) { return ((File)node).isFile(); }
public int getChildCount(Object parent) {
String[] children = ((File)parent).list();
if (children == null) return 0;
return children.length;
}
public Object getChild(Object parent, int index) {
String[] children = ((File)parent).list();
if ((children == null) || (index >= children.length)) return null;
return new File((File) parent, children[index]);
}
public int getIndexOfChild(Object parent, Object child) {
String[] children = ((File)parent).list();
if (children == null) return -1;
String childname = ((File)child).getName();
for(int i = 0; i < children.length; i++) {
if (childname.equals(children[i])) return i;
}
return -1;
}
// This method is only invoked by the JTree for editable trees.
// This TreeModel does not allow editing, so we do not implement
// this method. The JTree editable property is false by default.
public void valueForPathChanged(TreePath path, Object newvalue) {}
// Since this is not an editable tree model, we never fire any events,
// so we don't actually have to keep track of interested listeners.
public void addTreeModelListener(TreeModelListener l) {}
public void removeTreeModelListener(TreeModelListener l) {}
}
public static void main(String[] args) {
File root;
if (args.length > 0)
root = new File(args[0]);
else
root = new File(System.getProperty("user.home"));
FileTreeModel model = new FileTreeModel(root);
JTree tree = new JTree();
tree.setModel(model);
JScrollPane scrollpane = new JScrollPane(tree);
JFrame frame = new JFrame("FileTreeDemo");
frame.getContentPane().add(scrollpane, "Center");
frame.setSize(400,600);
frame.setVisible(true);
}
}
import javax.swing.*;
import javax.swing.table.AbstractTableModel;
class MVCTest07 extends JFrame{
static class YourModel extends AbstractTableModel{
Object[][] data={
{"..", ".."},
{"..", ".."},
};
public int getColumnCount(){
return data[0].length;
}
public int getRowCount(){
return data.length;
}
public Object getValueAt(int r,int c){
return data[r][c];
}
String [] columnName = { "..",".." };
public String getColumnName(int c){
return columnName[c];
}
public boolean isCellEditable(int r,int c){
boolean b=(c!=0)?true:false;
return b;
}
public void setValueAt(Object obj,int r,int c){
data[r][c]=obj;
}
}
static class JFrameTest extends JFrame{
public JFrameTest(){
YourModel mm=new YourModel();
JTable table=new JTable(mm);
add(new JScrollPane(table));
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(400, 200);
setVisible(true);
}
}
public static void main(String[] args) {
new JFrameTest();
}
}