use of java.awt.BorderLayout in project druid by alibaba.
the class DruidSqlDetailFrame method addTable.
/**
* 将表格添加到contentPanel对象内部。
*
* @param contentPanel JPanel对象
* @param 当前表格的标题
* @param data 当前表格的数据
*/
private void addTable(JPanel contentPanel, String title, ArrayList<LinkedHashMap<String, Object>> data) {
final JPanel content1 = new JPanel();
content1.setLayout(new BorderLayout());
content1.setBorder((TitledBorder) BorderFactory.createTitledBorder(title));
contentPanel.add(content1);
ColumnData colData = TableDataProcessor.row2col(data);
JTable table = new JTable();
DruidTableModel tableModel = new DruidTableModel(colData.getData());
table.setModel(tableModel);
TableColumn col = table.getColumnModel().getColumn(0);
col.setCellRenderer(new DruidTableCellRenderer());
final JTableHeader header1 = table.getTableHeader();
content1.add(header1, BorderLayout.NORTH);
content1.add(table);
}
use of java.awt.BorderLayout in project Smack by igniterealtime.
the class EnhancedDebugger method addInformationPanel.
private void addInformationPanel() {
// Create UI elements for connection information.
JPanel informationPanel = new JPanel();
informationPanel.setLayout(new BorderLayout());
// Add the Host information
JPanel connPanel = new JPanel();
connPanel.setLayout(new GridBagLayout());
connPanel.setBorder(BorderFactory.createTitledBorder("XMPPConnection information"));
JLabel label = new JLabel("Host: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
JFormattedTextField field = new JFormattedTextField(connection.getXMPPServiceDomain());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the Port information
label = new JLabel("Port: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(connection.getPort());
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's User information
label = new JLabel("User: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
userField = new JFormattedTextField();
userField.setMinimumSize(new java.awt.Dimension(150, 20));
userField.setMaximumSize(new java.awt.Dimension(150, 20));
userField.setEditable(false);
userField.setBorder(null);
connPanel.add(userField, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Creation time: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
field = new JFormattedTextField(new SimpleDateFormat("yyyy.MM.dd HH:mm:ss:SS"));
field.setMinimumSize(new java.awt.Dimension(150, 20));
field.setMaximumSize(new java.awt.Dimension(150, 20));
field.setValue(creationTime);
field.setEditable(false);
field.setBorder(null);
connPanel.add(field, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection's creationTime information
label = new JLabel("Status: ");
label.setMinimumSize(new java.awt.Dimension(150, 14));
label.setMaximumSize(new java.awt.Dimension(150, 14));
connPanel.add(label, new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0, 21, 0, new Insets(0, 0, 0, 0), 0, 0));
statusField = new JFormattedTextField();
statusField.setMinimumSize(new java.awt.Dimension(150, 20));
statusField.setMaximumSize(new java.awt.Dimension(150, 20));
statusField.setValue("Active");
statusField.setEditable(false);
statusField.setBorder(null);
connPanel.add(statusField, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0, 10, 2, new Insets(0, 0, 0, 0), 0, 0));
// Add the connection panel to the information panel
informationPanel.add(connPanel, BorderLayout.NORTH);
// Add the Number of sent packets information
JPanel packetsPanel = new JPanel();
packetsPanel.setLayout(new GridLayout(1, 1));
packetsPanel.setBorder(BorderFactory.createTitledBorder("Transmitted Packets"));
statisticsTable = new DefaultTableModel(new Object[][] { { "IQ", 0, 0 }, { "Message", 0, 0 }, { "Presence", 0, 0 }, { "Other", 0, 0 }, { "Total", 0, 0 } }, new Object[] { "Type", "Received", "Sent" }) {
// CHECKSTYLE:OFF
private static final long serialVersionUID = -6793886085109589269L;
@Override
public boolean isCellEditable(int rowIndex, int mColIndex) {
// CHECKSTYLE:ON
return false;
}
};
JTable table = new JTable(statisticsTable);
// Allow only single a selection
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
packetsPanel.add(new JScrollPane(table));
// Add the packets panel to the information panel
informationPanel.add(packetsPanel, BorderLayout.CENTER);
tabbedPane.add("Information", new JScrollPane(informationPanel));
tabbedPane.setToolTipTextAt(4, "Information and statistics about the debugged connection");
}
use of java.awt.BorderLayout in project jna by java-native-access.
the class AlphaMaskDemo2 method run.
public void run() {
// Must find a graphics configuration with a depth of 32 bits
GraphicsConfiguration gconfig = WindowUtils.getAlphaCompatibleGraphicsConfiguration();
frame = new JFrame("Alpha Mask Demo");
alphaWindow = new JWindow(frame, gconfig);
icon = new JLabel();
icon.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
alphaWindow.getContentPane().add(icon);
JButton quit = new JButton("Quit");
JLabel label = new JLabel("Drag this window by its image");
label.setHorizontalAlignment(SwingConstants.CENTER);
alphaWindow.getContentPane().add(label, BorderLayout.NORTH);
alphaWindow.getContentPane().add(quit, BorderLayout.SOUTH);
quit.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
System.exit(0);
}
});
MouseInputAdapter handler = new MouseInputAdapter() {
private Point offset;
public void mousePressed(MouseEvent e) {
if (SwingUtilities.isLeftMouseButton(e))
offset = e.getPoint();
}
public void mouseReleased(MouseEvent e) {
offset = null;
}
public void mouseDragged(MouseEvent e) {
if (offset != null) {
Window w = (Window) e.getSource();
Point where = e.getPoint();
where.translate(-offset.x, -offset.y);
Point loc = w.getLocationOnScreen();
loc.translate(where.x, where.y);
w.setLocation(loc.x, loc.y);
}
}
};
alphaWindow.addMouseListener(handler);
alphaWindow.addMouseMotionListener(handler);
JPanel p = new JPanel(new BorderLayout(8, 8));
p.setBorder(new EmptyBorder(8, 8, 8, 8));
p.setTransferHandler(new TransferHandler() {
private static final long serialVersionUID = 1L;
public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
List<DataFlavor> list = Arrays.asList(transferFlavors);
if (list.contains(URL_FLAVOR) || list.contains(URI_LIST_FLAVOR) || list.contains(DataFlavor.imageFlavor) || list.contains(DataFlavor.javaFileListFlavor)) {
return true;
}
if (DataFlavor.selectBestTextFlavor(transferFlavors) != null) {
return true;
}
System.err.println("No acceptable flavor found in " + Arrays.asList(transferFlavors));
return false;
}
public boolean importData(JComponent comp, Transferable t) {
try {
if (t.isDataFlavorSupported(URL_FLAVOR)) {
URL url = (URL) t.getTransferData(URL_FLAVOR);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
if (t.isDataFlavorSupported(URI_LIST_FLAVOR)) {
String s = (String) t.getTransferData(URI_LIST_FLAVOR);
String[] uris = s.split("[\r\n]");
if (uris.length > 0) {
URL url = new URL(uris[0]);
setImage(Toolkit.getDefaultToolkit().getImage(url));
return true;
}
return false;
}
if (t.isDataFlavorSupported(DataFlavor.imageFlavor)) {
Image image = (Image) t.getTransferData(DataFlavor.imageFlavor);
setImage(image);
return true;
}
if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
List<File> files = (List<File>) t.getTransferData(DataFlavor.javaFileListFlavor);
File f = files.get(0);
URL url = new URL("file://" + f.toURI().toURL().getPath());
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
DataFlavor flavor = DataFlavor.selectBestTextFlavor(t.getTransferDataFlavors());
if (flavor != null) {
Reader reader = flavor.getReaderForText(t);
char[] buf = new char[512];
StringBuilder b = new StringBuilder();
int count;
// encoding wrong
while ((count = reader.read(buf)) > 0) {
for (int i = 0; i < count; i++) {
if (buf[i] != 0)
b.append(buf, i, 1);
}
}
String html = b.toString();
Pattern p = Pattern.compile("<img.*src=\"([^\\\"\">]+)\"", Pattern.CANON_EQ | Pattern.UNICODE_CASE);
Matcher m = p.matcher(html);
if (m.find()) {
URL url = new URL(m.group(1));
System.out.println("Load image from " + url);
Image image = Toolkit.getDefaultToolkit().getImage(url);
setImage(image);
return true;
}
System.err.println("Can't parse text: " + html);
return false;
}
System.err.println("No flavor available: " + Arrays.asList(t.getTransferDataFlavors()));
} catch (UnsupportedFlavorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (Throwable e) {
e.printStackTrace();
}
return false;
}
});
p.add(new JLabel("<html><center>Drop an image with an alpha channel onto this window<br>" + "You may also adjust the overall transparency with the slider</center></html>"), BorderLayout.NORTH);
p.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
final JSlider slider = new JSlider(0, 255, 255);
slider.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
int value = slider.getValue();
WindowUtils.setWindowAlpha(alphaWindow, value / 255f);
}
});
p.add(slider, BorderLayout.SOUTH);
frame.getContentPane().add(p);
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
centerOnScreen(frame);
frame.setVisible(true);
WindowUtils.setWindowTransparent(alphaWindow, true);
alphaWindow.setLocation(frame.getX() + frame.getWidth() + 4, frame.getY());
try {
URL url = getClass().getResource("tardis.png");
if (url != null) {
setImage(Toolkit.getDefaultToolkit().getImage(url));
}
} catch (Exception e) {
}
}
use of java.awt.BorderLayout in project jna by java-native-access.
the class FilteredTextField method main.
/*
* A main entry point to test the FilteredTextField.
* @param args application arguments
*/
public static void main(String[] args) {
try {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
} catch (Exception e) {
e.printStackTrace();
}
JFrame jframe = new JFrame("Balloon Tips on FilteredTextField");
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.setSize(400, 75);
jframe.setLocation(400, 400);
JPanel jpanel = new JPanel();
jpanel.setLayout(new BorderLayout());
FilteredTextField ftfield = new FilteredTextField(10);
ftfield.setCharacters(LOWERCASE_CHARS);
ftfield.addCharacter('-');
ftfield.addCharacter('_');
ftfield.addCharacter(' ');
ftfield.setMaximumLength(10);
ftfield.setEntryError("Only lower case letters, hyphens, underscores, and spaces allowed.");
ftfield.setValidRegex("^a+[a-z-_ ]*");
ftfield.setValidError("The string must begin with the letter 'a'.");
jpanel.add(new JLabel("Type some text into either field"), BorderLayout.NORTH);
jpanel.add(ftfield, BorderLayout.CENTER);
jpanel.add(new FilteredTextField(10), BorderLayout.SOUTH);
jframe.getContentPane().add(jpanel);
jframe.setVisible(true);
}
use of java.awt.BorderLayout in project java-design-patterns by iluwatar.
the class Client method setup.
private void setup() {
setLayout(new BorderLayout());
JPanel panel = new JPanel();
add(jl, BorderLayout.SOUTH);
add(panel, BorderLayout.CENTER);
panel.setLayout(new GridLayout(6, 2));
panel.add(new JLabel("Name"));
panel.add(jtFields[0]);
panel.add(new JLabel("Contact Number"));
panel.add(jtFields[1]);
panel.add(new JLabel("Address"));
panel.add(jtAreas[0]);
panel.add(new JLabel("Deposit Number"));
panel.add(jtFields[2]);
panel.add(new JLabel("Order"));
panel.add(jtAreas[1]);
panel.add(clearButton);
panel.add(processButton);
clearButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
for (JTextArea i : jtAreas) {
i.setText("");
}
for (JTextField i : jtFields) {
i.setText("");
}
}
});
processButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
Order order = new Order(jtFields[0].getText(), jtFields[1].getText(), jtAreas[0].getText(), jtFields[2].getText(), jtAreas[1].getText());
jl.setText(sendRequest(order));
}
});
JRootPane rootPane = SwingUtilities.getRootPane(processButton);
rootPane.setDefaultButton(processButton);
setVisible(true);
}
Aggregations