JButton e setBorder

4 respostas
C

Galera, eu mudei a borda de um JButton com o setBorder, coloquei a borda como uma linha… só que agora essa borda agora fica colada com o texto, não tem mais aquele espaço natural… nao consegui fazer voltar… ja tentei criar um layout tb

alguem sabe pq aconteceu isso?

4 Respostas

B

Isso aki não resolve o seu problema, adicionar o espaço manualmente. :?

btnNovo = new JButton(" Novo "); btnNovo.setBorder(BorderFactory.createLineBorder(Color.BLACK));

falow… :wink:

C

Oi… para falar a verdade não :wink:

Porque o espaço da altura some tb… fica tudo grudado… ele realmente deixa de gerar sozinho mas ai fiz:

setBorder(…);

int h = getFontMetrics(getFont()).getHeight();

int w = getFontMetrics(getFont()).stringWidth(label);

setPreferredSize(new Dimension(w + 20, h + 10));

onde label é o label do button :shock: :lol:

B
C

brlima:
“API”:

public void setMargin(Insets m)

Sets space for margin between the button's border and the label. Setting to null will cause the button to use the default margin. The button's default Border object will use this value to create the proper margin. However, if a non-default border is set on the button, it is that Border object's responsibility to create the appropriate margin space (else this property will effectively be ignored).

[b]Parameters:[/b]
    m - the space between the border and the label

bem… pelo visto não é so

setBorder(…);

setMargin(new Insets(x,y,z,w);

pq tb não funcionou… vo ficar com a minha solução mesmo :wink:

Criado 30 de novembro de 2004
Ultima resposta 2 de dez. de 2004
Respostas 4
Participantes 3