106 lines
2.5 KiB
Java
106 lines
2.5 KiB
Java
package nt.UI.control;
|
|
|
|
import javax.swing.JPanel;
|
|
import javax.swing.JTextField;
|
|
import javax.swing.border.EmptyBorder;
|
|
import javax.swing.border.LineBorder;
|
|
import javax.swing.text.JTextComponent;
|
|
|
|
import java.awt.Color;
|
|
import java.awt.Component;
|
|
import java.awt.Font;
|
|
import java.awt.event.ActionListener;
|
|
|
|
import javax.swing.BoxLayout;
|
|
import javax.swing.JLabel;
|
|
import javax.swing.JButton;
|
|
import javax.swing.BorderFactory;
|
|
import javax.swing.Box;
|
|
import javax.swing.SwingConstants;
|
|
import javax.swing.SwingUtilities;
|
|
|
|
public class JSearchTextField extends JPanel{
|
|
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
private JLabel lblLens;
|
|
protected JTextField txtSearch;
|
|
protected JButton btnCancel;
|
|
private Component horizontalStrut;
|
|
private Component horizontalStrut_1;
|
|
|
|
public JSearchTextField() {
|
|
super();
|
|
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
|
|
|
Font symbols = new Font("LigatureSymbols", Font.PLAIN, 18);
|
|
|
|
horizontalStrut_1 = Box.createHorizontalStrut(20);
|
|
add(horizontalStrut_1);
|
|
lblLens = new JLabel("\uE116");
|
|
lblLens.setFont(symbols);
|
|
add(lblLens);
|
|
|
|
horizontalStrut = Box.createHorizontalStrut(10);
|
|
add(horizontalStrut);
|
|
|
|
txtSearch = new JTextField() {
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
@Override
|
|
public void setText(String txt) {
|
|
|
|
}
|
|
|
|
};
|
|
txtSearch.setText("search");
|
|
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
|
|
txtSearch.setBackground(getBackground());
|
|
add(txtSearch);
|
|
txtSearch.setColumns(10);
|
|
|
|
btnCancel = new JButton("\uE10f");
|
|
btnCancel.setHorizontalAlignment(SwingConstants.RIGHT);
|
|
btnCancel.setBorderPainted(false);
|
|
btnCancel.setFont(symbols);
|
|
btnCancel.setOpaque(false);
|
|
btnCancel.setVisible(false);
|
|
add(btnCancel);
|
|
|
|
setBorder(new LineBorder(Color.LIGHT_GRAY));
|
|
setPreferredSize(btnCancel.getPreferredSize());
|
|
setMinimumSize(btnCancel.getMinimumSize());
|
|
}
|
|
|
|
public void addActionListener(ActionListener l) {
|
|
this.btnCancel.addActionListener(l);
|
|
}
|
|
public void removeActionListener(ActionListener l) {
|
|
this.btnCancel.removeActionListener(l);
|
|
}
|
|
public void showCancelButton(boolean b) {
|
|
this.btnCancel.setVisible(b);
|
|
System.out.println(b);
|
|
revalidate();
|
|
|
|
}
|
|
|
|
@Override
|
|
public void setBackground(Color bg) {
|
|
super.setBackground(bg);
|
|
for(Component c : getComponents()) {
|
|
c.setBackground(bg);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void setForeground(Color fg) {
|
|
super.setForeground(fg);
|
|
for(Component c : getComponents()) {
|
|
c.setForeground(fg);
|
|
}
|
|
}
|
|
|
|
|
|
}
|