final JFrame f = new JFrame(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); final JLabel l = new JLabel(); f.getContentPane().add(l, BorderLayout.CENTER); f.getContentPane().add(b, BorderLayout.SOUTH); f.setLocation(100, 100); f.pack(); f.setVisible(true);
constraints.fill = GridBagConstraints.BOTH; JLabel l = new JLabel("You have got 2 new Messages."); panel.add(l, constraints); constraints.gridx++; constraints.weightx = 0f; b.setMargin(new Insets(1, 4, 1, 4)); b.setFocusable(false); panel.add(b, constraints); dialog.setUndecorated(true); dialog.setSize(300, 100); dialog.setLocation(screenSize.width - dialog.getWidth(), screenSize.height - taskBarSize - dialog.getHeight()); lpg = new LinearGradientPaint(0, 0, 0, dialog.getHeight() / 2,
JFrame frame = new JFrame(); frame.setTitle("Test Background"); frame.setLocation(200, 100); frame.setSize(600, 400); frame.addWindowListener(new WindowAdapter() { frame.setVisible(true);
import java.awt.BorderLayout;import java.awt.Dimension;import java.awt.FlowLayout;import java.awt.Point;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.GroupLayout;import javax.swing.GroupLayout.Alignment;import javax.swing.JButton;import javax.swing.JDialog;import javax.swing.JFileChooser;import javax.swing.JFrame;import javax.swing.JLabel;import javax.swing.JPanel;import javax.swing.JTextField;import javax.swing.LayoutStyle.ComponentPlacement;import javax.swing.border.EmptyBorder;import javax.swing.filechooser.FileFilter;import javax.swing.filechooser.FileNameExtensionFilter;public class ConfigureDialog extends JDialog implements ActionListener{private static final long serialVersionUID=1L;private final JPanel contentPanel=new JPanel();private JTextField driverPathTextField;private JLabel lblDriverPath;private JButton btnBrowse;public static void main(String[]args){try{ConfigureDialog dialog=new ConfigureDialog(new JFrame());dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);dialog.setVisible(true);}catch(Exception e){e.printStackTrace();}} public ConfigureDialog(JFrame parent){super(parent,"",true);if(parent!=null){Dimension parentSize=parent.getSize();Point p=parent.getLocation();setLocation(p.x+parentSize.width+100,p.y+parentSize.height/1);} setBounds(100,100,479,141);getContentPane().setLayout(new BorderLayout());contentPanel.setBorder(new EmptyBorder(5,5,5,5));getContentPane().add(contentPanel,BorderLayout.CENTER);{lblDriverPath=new JLabel("Driver Path : ");} {driverPathTextField=new JTextField(System.getProperty("web.ie.driver"));driverPathTextField.setColumns(10);} btnBrowse=new JButton("Browse");GroupLayout gl_contentPanel=new GroupLayout(contentPanel);gl_contentPanel.setHorizontalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addContainerGap().addComponent(lblDriverPath).addPreferredGap(ComponentPlacement.RELATED).addGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addComponent(btnBrowse).addComponent(driverPathTextField,GroupLayout.DEFAULT_SIZE,207,Short.MAX_VALUE)).addContainerGap()));gl_contentPanel.setVerticalGroup(gl_contentPanel.createParallelGroup(Alignment.LEADING).addGroup(gl_contentPanel.createSequentialGroup().addGap(5).addGroup(gl_contentPanel.createParallelGroup(Alignment.BASELINE).addComponent(driverPathTextField,GroupLayout.PREFERRED_SIZE,GroupLayout.DEFAULT_SIZE,GroupLayout.PREFERRED_SIZE).addComponent(lblDriverPath)).addPreferredGap(ComponentPlacement.UNRELATED).addComponent(btnBrowse).addContainerGap(21,Short.MAX_VALUE)));contentPanel.setLayout(gl_contentPanel);{JPanel buttonPane=new JPanel();buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));getContentPane().add(buttonPane,BorderLayout.SOUTH);{JButton okButton=new JButton("OK");okButton.setActionCommand("OK");okButton.addActionListener(this);buttonPane.add(okButton);getRootPane().setDefaultButton(okButton);} {JButton cancelButton=new JButton("Cancel");cancelButton.setActionCommand("Cancel");cancelButton.addActionListener(this);buttonPane.add(cancelButton);}} btnBrowse.addActionListener(this);}@Override public void actionPerformed(ActionEvent e){if("Cancel".contains(e.getActionCommand())){dispose();}else if("Browse".contains(e.getActionCommand())){JFileChooser fileopen=new JFileChooser();FileFilter filter=new FileNameExtensionFilter("exe file","exe");fileopen.addChoosableFileFilter(filter);fileopen.setAcceptAllFileFilterUsed(false);fileopen.setFileFilter(filter);fileopen.setFileSelectionMode(JFileChooser.FILES_ONLY);int ret=fileopen.showOpenDialog(this);if(ret==JFileChooser.APPROVE_OPTION){File file=fileopen.getSelectedFile();System.out.println(file);driverPathTextField.setText(file.getPath());}}else if("OK".contains(e.getActionCommand())){System.setProperty("web.ie.driver",driverPathTextField.getText());dispose();}}}
import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JButton; public class CustomDialog extends JDialog { private JPanel myPanel = null; private JButton yesButton = null; private JButton noButton = null; public CustomDialog(JFrame frame, boolean modal, String myMessage) { super(frame, modal); myPanel = new JPanel(); getContentPane().add(myPanel); myPanel.add(new JLabel(myMessage)); yesButton = new JButton("Yes"); myPanel.add(yesButton); noButton = new JButton("No"); myPanel.add(noButton); pack(); //setLocationRelativeTo(frame); setLocation(200, 200); // <-- setVisible(true); } }
import javax.swing.*; import java.awt.*; public class test extends JWindow{ public test(){ super(); this.setSize(500, 400); this.setLocation(50, 50); setBackground(new Color(0,0,0,0)); // this is the critical line - that fourth 0 represents alpha (or opacity) setAlwaysOnTop( true ); // keeps it in the foreground so you don't click away from it - note that clicks on the transparent part DO pass through to the desktop, at least on Lion JLabel testLabel = new JLabel("Floating text hah"); this.add(testLabel); } public static void main(String[] args){ System.out.println("Sup"); test t = new test(); t.setVisible(true); } }
public void run() { if (pack) { w.pack(); // Make sure the window is positioned away from // any toolbars around the display borders w.setLocation(100, 100); } if (size != null) w.setSize(size.width, size.height); w.setVisible(true); } });
public static void showCenterScreen(Window window) { try { Rectangle bound = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice() .getDefaultConfiguration().getBounds(); window.setLocation(bound.x + (bound.width - window.getWidth()) / 2, bound.y + (bound.height - window.getHeight()) / 2); } catch (Exception e) { LOGGER.error("Cannot center the window to the screen", e); //$NON-NLS-1$ } window.setVisible(true); }
table.setPreferredScrollableViewportSize(table.getPreferredSize()); JScrollPane scrollPane = new JScrollPane(table); getContentPane().add(scrollPane); public void run() { TableCheckBox frame = new TableCheckBox(); frame.setDefaultCloseOperation(EXIT_ON_CLOSE); frame.pack(); frame.setLocation(150, 150); frame.setVisible(true);
final int taskBarSize = scnMax.bottom; setLocation(screenSize.width - getWidth(), screenSize.height - taskBarSize - getHeight()); l.setOpaque(false); c.add(l, constraints); b.setFocusable(false); c.add(b, constraints);
import java.awt.Dimension; import javax.swing.*; public class testDialog { public static void main(String []args) { JDialog d=new JDialog(); JInternalFrame i=new JInternalFrame("HI",false,false,false,false); i.setPreferredSize(new Dimension(100,100)); d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); d.setTitle("Wait dialog"); d.add(i); d.pack(); d.setPreferredSize(new Dimension(100,100)); d.setLocation(300,300); d.setAlwaysOnTop(true); d.setVisible(true); } }
/** * Packs, centers, and shows the specified window on the screen. * @param window the window to pack, center, and show * @param center {@code true} if the window must be centered; {@code false} otherwise */ private void packCenterShow(Window window, boolean center) { Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); window.pack(); if (center) { window.setLocation((screenSize.width - window.getWidth()) / 2, (screenSize.height - window.getHeight()) / 2); } window.setVisible(true); }
public static void showCenterScreen(Window window, Component parent) { if (parent == null) { showCenterScreen(window); } else { Dimension sSize = parent.getSize(); Dimension wSize = window.getSize(); Point p = parent.getLocationOnScreen(); window.setLocation(p.x + ((sSize.width - wSize.width) / 2), p.y + ((sSize.height - wSize.height) / 2)); window.setVisible(true); } }
someComboBox.setDataList(listSomeAnotherString); frame = new JFrame(); frame.setLayout(new GridLayout(0, 1, 10, 10)); frame.add(someTextField); frame.add(someComboBox); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setLocation(100, 100); frame.pack(); frame.setVisible(true);
import java.awt.Dimension; import javax.swing.JButton; import javax.swing.JDialog; public class Dialog extends JDialog { private JButton done; public Dialog() { done = new JButton("Done"); this.add(done); this.setSize(new Dimension(400,200)); } public void setDialogLocation(int x, int y) { this.setLocation(x, y); } }
import javax.swing.*; import java.awt.Dimension; class MyFrame extends JFrame { public MyFrame() { setTitle("My Empty Frame"); setPreferredSize(new Dimension(300, 200)); // default size is 0,0 setLocation(10, 200); // default is 0,0 (top left corner) pack(); setVisible(true); } public static void main(String[] args) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { new MyFrame(); } }); } }
//other imports import java.awt.Toolkit; public class test { public static void main(String[] args) { Window wnd = new Window(new Frame()); //Of course this set the window 100 px to the right // and 100 to the bottom wnd.setLocation(100, 100); //You use the Toolkit class!! //Now your window has the same size of your screen!! wnd.setSize(Toolkit.getDefaultToolkit().getScreenSize()); wnd.setBackground(Color.red); wnd.setVisible(true); } }
private final JFrame f = new JFrame(); private final JTextField tf = new JTextField(25); private final JTextArea ta = new JTextArea(15, 25); this.kind = kind; f.setTitle("Echo " + kind); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.getRootPane().setDefaultButton(send); f.add(tf, BorderLayout.NORTH); f.add(new JScrollPane(ta), BorderLayout.CENTER); f.add(send, BorderLayout.SOUTH); f.setLocation(kind.offset, 300); f.pack(); send.addActionListener(this); ta.setLineWrap(true); f.setVisible(true); thread.start();
public static void showCenterScreen(Window window, ColorLayerUI layer) { Container container = getContentPane(layer); if (container == null) { JMVUtils.showCenterScreen(window); } else { Dimension sSize = container.getSize(); Dimension wSize = window.getSize(); Point p = container.getLocationOnScreen(); window.setLocation(p.x + ((sSize.width - wSize.width) / 2), p.y + ((sSize.height - wSize.height) / 2)); window.setVisible(true); layer.hideUI(); } }
private JFrame frame = new JFrame("sssssssss"); private JButton tip1Null = new JButton(" test button "); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(tip1Null, BorderLayout.CENTER); frame.setLocation(150, 150); frame.setPreferredSize(new Dimension(310, 75)); frame.setLocationRelativeTo(null); frame.pack(); frame.setVisible(true);