Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Need to change View More Details JButton size using NetBeans /* * To change this

ID: 3892190 • Letter: N

Question

Need to change View More Details JButton size using NetBeans

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package GUI;

import Model.Car;
import java.awt.Button;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import javax.imageio.ImageIO;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

/**
*
* @author msalehan
*/
public class InventoryItemPanel extends JPanel{
private JLabel label = new JLabel();

private Button addCar = new Button ("Add Car");

private Button button = new Button("View More Details");


  


  
Car car;
ArrayList cars;

  
  
public void buttonClicked(){
ViewCarForm cform = new ViewCarForm (cars,car);
cform.setVisible(true);

  
}
  
public void setPreferredSize (){
  
button.setSize(156, 29);

button.setPreferredSize(new Dimension (156,29));

  
  
}

//ArrayList cars, Car car
public InventoryItemPanel (ArrayList cars, Car car) throws IOException{
  
  
button.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
button.setSize(156, 29);
buttonClicked();

}
});

  

addCar.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
AddCarForm frame = new AddCarForm();
frame.setVisible (true);
  
}
});
  

BufferedImage carPicture;
  
try {
carPicture = ImageIO.read (new File (".//src//images//" + car.getMake() + car.getModel() + ".jpg"));

} catch (Exception e) {
carPicture = ImageIO.read(new File (".//src//images//"));
}
ImageIcon imageIcon = new ImageIcon(carPicture.getScaledInstance(100, 110,10));
// carPicture.getScaledInstance (100,110, java.awt.Image.SCALE_DEFAULT)
  
JLabel picLabel = new JLabel (imageIcon);
add (picLabel);
setLayout (new GridLayout (3,10));
button.setSize(156, 29);
this.cars= cars;
this.car = car;


  
  
label.setText("

"+ car.getMake()+ " "+ car.getModel() + "
" + car.getMiles()+" miles" + "
$" +car.getPrice() + "

" );
  
add (label);
  
add(button);
button.setSize(156, 29);
  
  

Explanation / Answer

The solution to your problem is this:-

GridLayout ignores the buttons' preferred size.

Replace the JPanel syntax to:-

Please let me know in case of any clarifications required. Thanks!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote