Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- button.setBorderPainted(false);
- button.setContentAreaFilled(false);
- button.setOpaque(true);
- button.setOpaque(false);
- button.setFocusPainted(false);
- button.setBorderPainted(false);
- button.setContentAreaFilled(false);
- setBorder(BorderFactory.createEmptyBorder(0,0,0,0)); // Especially important
- JButton addBtn=new JButton("+");
- addBtn.setBounds(x_pos,y_pos,30,25);
- addBtn.setBorder(new RoundedBorder(10));//10 is the radius
- addBtn.setForeground(Color.BLUE);
- private static class RoundedBorder implements Border {
- private int radius;
- RoundedBorder(int radius) {
- this.radius = radius;
- }
- public Insets getBorderInsets(Component c) {
- return new Insets(this.radius+1, this.radius+1, this.radius+2, this.radius);
- }
- public boolean isBorderOpaque() {
- return true;
- }
- public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
- g.drawRoundRect(x,y,width-1,height-1,radius,radius);
- }
- }
- button.setOpaque(false);
- class JImageButton extends JComponent implements MouseListener {
- private BufferedImage img = null;
- public JImageButton(BufferedImage img) {
- this.img = img;
- setMinimumSize(new Dimension(img.getWidth(), img.getHeight()));
- setOpaque(false);
- addMouseListener(this);
- }
- public void paintComponent(Graphics g) {
- g.drawImage(img, 0, 0, img.getWidth(), img.getHeight(), null);
- }
- @Override
- public void mouseClicked(MouseEvent e) {
- }
- @Override
- public void mouseEntered(MouseEvent e) {
- }
- @Override
- public void mouseExited(MouseEvent e) {
- }
- @Override
- public void mousePressed(MouseEvent e) {
- }
- @Override
- public void mouseReleased(MouseEvent e) {
- }
- }
Add Comment
Please, Sign In to add comment