package nt.UI.control; import java.awt.Color; import java.awt.Component; import java.awt.FlowLayout; import java.awt.Font; import java.awt.event.ActionListener; import javax.swing.Box; import javax.swing.BoxLayout; import javax.swing.JButton; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JTextField; import javax.swing.SwingConstants; import javax.swing.border.EmptyBorder; import javax.swing.border.LineBorder; import nt.UI.NtUIHelper; import java.awt.Dimension; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; public class JSearchTextField extends JPanel{ private static final long serialVersionUID = 1L; private JLabel lblLens; protected JTextField txtSearch; protected JButton btnCancel; private Component horizontalStrut; public JSearchTextField() { super(); Font symbols = NtUIHelper.getSymbolFont().deriveFont(18f); GridBagLayout gridBagLayout = new GridBagLayout(); gridBagLayout.columnWidths = new int[]{42, 31, 255, 53, 0}; gridBagLayout.rowHeights = new int[]{29, 0}; gridBagLayout.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; gridBagLayout.rowWeights = new double[]{1.0, Double.MIN_VALUE}; setLayout(gridBagLayout); lblLens = new JLabel("\uE116"); lblLens.setFont(symbols); GridBagConstraints gbc_lblLens = new GridBagConstraints(); gbc_lblLens.fill = GridBagConstraints.VERTICAL; gbc_lblLens.insets = new Insets(0, 0, 0, 5); gbc_lblLens.gridx = 0; gbc_lblLens.gridy = 0; add(lblLens, gbc_lblLens); horizontalStrut = Box.createHorizontalStrut(10); GridBagConstraints gbc_horizontalStrut = new GridBagConstraints(); gbc_horizontalStrut.fill = GridBagConstraints.VERTICAL; gbc_horizontalStrut.anchor = GridBagConstraints.WEST; gbc_horizontalStrut.insets = new Insets(0, 0, 0, 5); gbc_horizontalStrut.gridx = 1; gbc_horizontalStrut.gridy = 0; add(horizontalStrut, gbc_horizontalStrut); txtSearch = new JTextField(); txtSearch.setText("search"); txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0)); txtSearch.setBackground(getBackground()); GridBagConstraints gbc_txtSearch = new GridBagConstraints(); gbc_txtSearch.fill = GridBagConstraints.BOTH; gbc_txtSearch.insets = new Insets(0, 0, 0, 5); gbc_txtSearch.gridx = 2; gbc_txtSearch.gridy = 0; add(txtSearch, gbc_txtSearch); txtSearch.setColumns(10); btnCancel = new JButton("\uE10f"); btnCancel.setBorderPainted(false); btnCancel.setFont(symbols); btnCancel.setOpaque(false); GridBagConstraints gbc_btnCancel = new GridBagConstraints(); gbc_btnCancel.fill = GridBagConstraints.VERTICAL; gbc_btnCancel.gridx = 3; gbc_btnCancel.gridy = 0; add(btnCancel, gbc_btnCancel); setMinimumSize(btnCancel.getMinimumSize()); setBorder(new LineBorder(Color.LIGHT_GRAY)); setPreferredSize(new Dimension(376, 56)); } 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); 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); } } }