import java.awt.*; import java.awt.event.*; import javax.swing.*; public class hjg extends JFrame { private JPanel contentPane; private JTextArea jTextArea2; private JScrollPane jScrollPane1; private JButton jButton3; private JButton jButton4; private JButton jButton5; private JPanel jPanel1; public hjg() { super(); initializeComponent(); this.setVisible(true); } private void initializeComponent() { contentPane = (JPanel)this.getContentPane(); jTextArea2 = new JTextArea(); jScrollPane1 = new JScrollPane(); jButton3 = new JButton(); jButton4 = new JButton(); jButton5 = new JButton(); jPanel1 = new JPanel(); // // contentPane // contentPane.setLayout(null); addComponent(contentPane, jPanel1, 4,4,374,263); // // jTextArea2 // jTextArea2.setText("jTextArea2"); // // jScrollPane1 // jScrollPane1.setViewportView(jTextArea2); // // jButton3 // jButton3.setText("jButton3"); jButton3.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton3_actionPerformed(e); } }); // // jButton4 // jButton4.setText("jButton4"); jButton4.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton4_actionPerformed(e); } }); // // jButton5 // jButton5.setText("jButton5"); jButton5.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { jButton5_actionPerformed(e); } }); // // jPanel1 // jPanel1.setLayout(null); addComponent(jPanel1, jScrollPane1, 18,11,339,132); addComponent(jPanel1, jButton3, 22,177,83,28); addComponent(jPanel1, jButton4, 137,177,83,28); addComponent(jPanel1, jButton5, 265,176,83,28); // // hjg // this.setTitle("title"); this.setLocation(new Point(0, 0)); this.setSize(new Dimension(390, 300)); this.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); } private void addComponent(Container container,Component c,int x,int y,int width,int height) { c.setBounds(x,y,width,height); container.add(c); } private void jButton3_actionPerformed(ActionEvent e) { } private void jButton4_actionPerformed(ActionEvent e) { private void jButton5_actionPerformed(ActionEvent e) { } public static void main(String[] args) { JFrame.setDefaultLookAndFeelDecorated(true); JDialog.setDefaultLookAndFeelDecorated(true); try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); } catch (Exception ex) { System.out.println("Failed loading L&F: "); System.out.println(ex); } new hjg(); } }
BrokenArrows wrote: the code that im supplying with this shows how to easily position items where ever you like.......
......
Amaru wrote: That's probably good code, but i actually eventually managed to get gridbaglayout working, which is perfect. Thanks for posting your reply though. One more question, i want there to be pictures instead of buttons, as in i'm drawing my own buttons. Right now i'm using icons, but they only cover a partial area of the button themselves, leaving a different colour border, which just looks stupid. Is there any way to make the whole button an image?
BrokenArrows wrote: i wasent passing it off as my own. I got this from a gui builder originally but since then i always use this way to place my items. I find it much easier to use than the other layout managers
Imposter wrote: One solution is to program your own button class which handles clicks on the image using mouse events. You can also include a second image to give it a clicked look.