setBounds

buttonPlus.setBounds(new Rectangle(115, 215, 175, 35));

i do not know but the above line does not change the dimensions of JButton, well does not create any compilation error..

[189 byte] By [shagya] at [2007-11-27 10:11:42]
# 1

what layout manager is having the parent of this button?

Aniruddha-Herea at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 2

setBounds

method should be used when you dont use any layout managers in your gui.

AnanSmritia at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 3

Mybe shagy try to use some source like this:

getContentPane().setLayout(null);

button_cancelar= new JButton();

button_cancelar.setText("Cancelar");

getContentPane().add(button_cancelar);

button_cancelar.setBounds(220, 80, 120, 30);

button_cancelar.setIcon(new ImageIcon("cancelar.png"));

i developed it in a JInternalFrame, but in another case you can programming in JFrame, Frame etc...

Full Source

/*

* AltaDoctor.java

*

* Created on 17 de julio de 2005, 09:23 PM

*/

/**

*

* @author carlo

*/

import java.io.*;

import java.sql.*;

import java.awt.*;

import java.util.*;

import java.lang.*;

import javax.swing.*;

import java.awt.event.*;

public class AltaMedicamentoCultivo extends JInternalFrame {

/** Creates new form AltaDoctor */

public AltaMedicamentoCultivo() {

initComponents();

setSize(400,150);

}

/** This method is called from within the constructor to

* initialize the form.

* WARNING: Do NOT modify this code. The content of this method is

* always regenerated by the Form Editor.

*/

private void initComponents() {//GEN-BEGIN:initComponents

setFrameIcon(new ImageIcon("medicamento.png"));

label_nombre= new JLabel();

campotxt_medicamento= new JTextField();

button_cancelar= new JButton();

button_aceptar= new JButton();

getContentPane().setLayout(null);

setClosable(true);

setIconifiable(true);

setTitle("Altas Medicamentos Cultivos");

label_nombre.setText("Medicamento");

getContentPane().add(label_nombre);

label_nombre.setBounds(20, 20, 100, 16);

getContentPane().add(campotxt_medicamento);

campotxt_medicamento.setBounds(120, 20, 160, 20);

button_cancelar.setText("Cancelar");

getContentPane().add(button_cancelar);

button_cancelar.setBounds(220, 80, 120, 30);

button_cancelar.setIcon(new ImageIcon("cancelar.png"));

button_aceptar.setText("Aceptar");

getContentPane().add(button_aceptar);

button_aceptar.setBounds(50, 80, 120, 30);

button_aceptar.setIcon(new ImageIcon("aceptar.png"));

button_aceptar.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try{

/* Aplicaremos el metodo alta medicamento*/

alta_medicamento();

}catch(Exception sqle){}

}

});

button_cancelar.addActionListener(new ActionListener() {

public void actionPerformed(ActionEvent e) {

try{

dispose();

}catch(Exception sqle){}

}

});

campotxt_medicamento.addKeyListener(new KeyListener(){

public void keyReleased(KeyEvent e) {

try{

if(e.getKeyCode()==10)

{

alta_medicamento();

}

}catch(Exception ex){}

}

public void keyTyped(KeyEvent e) {

try{

}catch(Exception ex){}

}

public void keyPressed(KeyEvent e) {

try{

}catch(Exception ex){}

}

});

pack();

}

public void mensaje(String estado){

JOptionPane.showMessageDialog(this,estado);

}

public void alta_medicamento(){

try{

medicamento= campotxt_medicamento.getText();

if(medicamento.equals("")){

mensaje("INGRESE UN MEDICAMENTO");

}

else{

Class.forName("com.mysql.jdbc.Driver").newInstance();

conexion = DriverManager.getConnection("jdbc:mysql://localhost/prister");

statement = conexion.createStatement();

System.out.println("INSERTANDO MEDICAMENTO "+medicamento);

int insertar=statement.executeUpdate("insert into medicamento values('"+medicamento+"');");

System.out.println("LISTO ");

mensaje("MEDICAMENTO REGISTRADO EXITOSAMENTE");

campotxt_medicamento.setText("");

}

}catch(Exception altame){}

}

private Connection conexion;

private Statement statement;

private ResultSet resultset;

private String medicamento;

private JTextField campotxt_medicamento;

private JLabel label_nombre;

private JButton button_cancelar;

private JButton button_aceptar;

}

ErnestoCarloa at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 4

the button is inside a JPanel following gridlayout

shagya at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 5

he button is inside a JPanel following gridlayout

there one more Jpanel which again contain buttons,

but size of button in both these panels is different that is why i tryed to use setbounds but there is affect of setBound method...

shagya at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 6

well i do not understand what kind of code is this

public class AltaMedicamentoCultivo extends JInternalFrame {

shagya at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 7

Your class AltaMedicamentoCultivo

extends JInternalFrame

AnanSmritia at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...
# 8

no the big code above is AltaMedicamentoCultivo ,,, and i do not understand

shagya at 2007-7-28 15:15:19 > top of Java-index,Desktop,Core GUI APIs...