JSearchBar WIP
parent
a3205a1cce
commit
6d33fb730e
|
@ -0,0 +1,20 @@
|
|||
package nt.UI;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.FontFormatException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class NtUIHelper {
|
||||
|
||||
public static Font getSymbolFont() {
|
||||
try {
|
||||
return Font.createFont(Font.TYPE1_FONT, NtUIHelper.class.getResourceAsStream("/nt/UI/LigatureSymbols-2.11.ttf"));
|
||||
} catch (FontFormatException | IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return Font.getFont("Arial");
|
||||
}
|
||||
|
||||
}
|
|
@ -113,7 +113,7 @@ public class JSearchBarController extends KeyAdapter implements DocumentListener
|
|||
@Override
|
||||
public void keyPressed(KeyEvent e) {
|
||||
if(this.searchBar.completionActive) {
|
||||
JList<?> list = searchBar.dropDown.list;
|
||||
JList<String> list = searchBar.dropDown.list;
|
||||
int index = list.getSelectedIndex();
|
||||
if(e.getKeyCode() == KeyEvent.VK_DOWN) {
|
||||
index = index >= list.getModel().getSize()? list.getModel().getSize()-1:++index;
|
||||
|
@ -122,6 +122,12 @@ public class JSearchBarController extends KeyAdapter implements DocumentListener
|
|||
}
|
||||
list.setSelectedIndex(index);
|
||||
list.ensureIndexIsVisible(index);
|
||||
|
||||
if(e.getKeyCode()==KeyEvent.VK_ENTER) {
|
||||
searchBar.txtSearch.setText(list.getSelectedValue());
|
||||
System.out.println(list.getSelectedValue());
|
||||
System.out.println(searchBar.txtSearch.getText());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -165,12 +171,12 @@ public class JSearchBarController extends KeyAdapter implements DocumentListener
|
|||
|
||||
@Override
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
String val = searchBar.dropDown.list.getSelectedValue();
|
||||
if(val != null) {
|
||||
JTextField field = searchBar.txtSearch;
|
||||
field.setText(val);
|
||||
field.setCaretPosition(field.getText().length());
|
||||
}
|
||||
// String val = searchBar.dropDown.list.getSelectedValue();
|
||||
// if(val != null) {
|
||||
// JTextField field = searchBar.txtSearch;
|
||||
// field.setText(val);
|
||||
// field.setCaretPosition(field.getText().length());
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,8 @@ import javax.swing.border.EmptyBorder;
|
|||
import javax.swing.border.LineBorder;
|
||||
import javax.swing.text.JTextComponent;
|
||||
|
||||
import nt.UI.NtUIHelper;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Font;
|
||||
|
@ -33,7 +35,7 @@ public class JSearchTextField extends JPanel{
|
|||
super();
|
||||
setLayout(new BoxLayout(this, BoxLayout.X_AXIS));
|
||||
|
||||
Font symbols = new Font("LigatureSymbols", Font.PLAIN, 18);
|
||||
Font symbols = NtUIHelper.getSymbolFont();
|
||||
|
||||
horizontalStrut_1 = Box.createHorizontalStrut(20);
|
||||
add(horizontalStrut_1);
|
||||
|
@ -44,15 +46,7 @@ public class JSearchTextField extends JPanel{
|
|||
horizontalStrut = Box.createHorizontalStrut(10);
|
||||
add(horizontalStrut);
|
||||
|
||||
txtSearch = new JTextField() {
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
public void setText(String txt) {
|
||||
|
||||
}
|
||||
|
||||
};
|
||||
txtSearch = new JTextField();
|
||||
txtSearch.setText("search");
|
||||
txtSearch.setBorder(new EmptyBorder(0, 0, 0, 0));
|
||||
txtSearch.setBackground(getBackground());
|
||||
|
|
|
@ -5,6 +5,7 @@ import javax.swing.UIManager;
|
|||
import javax.swing.UnsupportedLookAndFeelException;
|
||||
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||
|
||||
import nt.UI.NtUIHelper;
|
||||
import nt.UI.control.JSearchBar;
|
||||
import nt.UI.control.JSearchTextField;
|
||||
import nt.UI.control.interfaces.SearchBarFinder;
|
||||
|
@ -31,6 +32,7 @@ public class UITestMain extends JFrame{
|
|||
}
|
||||
}
|
||||
|
||||
NtUIHelper.getSymbolFont();
|
||||
|
||||
UITestMain frame = new UITestMain();
|
||||
frame.setVisible(true);
|
||||
|
|
Loading…
Reference in New Issue