The question is in the title.
Here's my code :
JButton button = new JButton("JOUER", new ImageIcon(getClass().getResource("template.png")));
button.setBounds(0, 0, 215, 84);
button.setBackground(new Color(0,0,0,0));
button.setFont(new Font("Bebas Neue Bold", Font.TRUETYPE_FONT, 50));
button.setForeground(Color.WHITE);
button.setVerticalTextPosition(SwingConstants.CENTER);
button.setHorizontalTextPosition(SwingConstants.CENTER);
Here's the result :
And I just want to know if is it possible to outline my text.
Here's the result I want to have:
Related
when i enable or request focus in text area the focus or caret anything u name it, it located at left. but when i start typing, it change to right.
please help me to make it on right when request focus(true);
this is the properties of textarea:
textManualIn = new JTextArea();
textManualIn.setLocale(new Locale("ar", "AE"));
textManualIn.setMinimumSize(new Dimension(5, 22));
textManualIn.setPreferredSize(new Dimension(5, 22));
textManualIn.setFocusCycleRoot(true);
textManualIn.setFocusTraversalPolicyProvider(true);
textManualIn.setCursor(Cursor.getPredefinedCursor(Cursor.TEXT_CURSOR));
textManualIn.setRequestFocusEnabled(true);
textManualIn.setFont(new Font("Calibri", Font.PLAIN, 14));
textManualIn.setSelectionColor(new Color(153, 255, 255));
textManualIn.setMargin(new Insets(2, 5, 2, 5));
textManualIn.applyComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
textManualIn.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
textManualIn.setCaretColor(Color.BLACK);
textManualIn.setBackground(new Color(255, 255, 255));
mainmanual.add(status);//add to Jpanel
This is not perfect, but you can try this code:
textManualIn.setText(" "); // one space
// And use one of the following
textManualIn.setCaretPosition(0);
// -or-
textManualIn.select(0, 1);
I 'm trying to wrap a JTextPane with a JScrollPane, and I need the background to be transparent.
Here's my code:
public CharPanel(){
super.setLayout(null);
JButton LButton = new JButton("<");
LButton.setBounds(0, 300, 50, 50);
super.add(LButton);
JButton RButton = new JButton(">");
RButton.setBounds(950, 300, 50, 50);
super.add(RButton);
JTextPane Bio = new JTextPane();
Bio.setBackground(new Color(0, 0, 0, 0));
JScrollPane BioScroll = new JScrollPane(Bio);
BioScroll.setBackground(new Color(0, 0, 0, 0));
BioScroll.setBounds(0, 500, 1000, 150);
super.add(BioScroll);
}
This is what it looks like normally: https://gyazo.com/db7e4d2a5668b36ffc617cefb1423fc4
This is what it looks like after I enter a character: https://gyazo.com/1509d952005195d6e14365f0ae2da69a
See the weird visual bug?
Bio.setBackground(new Color(0, 0, 0, 0));
Don't use Colors with an alpha value. This breaks Swing painting rules and Swing don't know how to paint the component properly and you get painting artifacts.
For full transparency just use:
component.setOpaque( false );
Check out Backgrounds With Transparency for more information on this and a solution if you need to use partial transparency.
why if i have an image background i cant see all my buttons? only if my arrow go on button i see it..
this is my jlabel with background:
JLabel sfondo = new JLabel("");
sfondo.setBounds(0, 0, 832, 527);
contentPane.add(sfondo);
sfondo.setIcon(new ImageIcon(
"C:\\Users\\bocci\\workspace\\it's time of the series\\src\\immagini\\icone\\sfondo.jpg"));
sfondo.setIcon(icona3.newicona(patchsfondo, sfondo));
and i have 5 jbuttons
JButton btnOpzioni = new JButton("Opzioni");
btnOpzioni.setBounds(497, 5, 67, 23);
contentPane.add(btnOpzioni);
i see only first button.
I am trying to add 2 JTextPane to one scrollPane. But it not scrolling. What am I doing wrong?
JScrollPane scrollPane = new JScrollPane();
scrollPane.setBounds(402, 211, 178, 193);
frame.getContentPane().add(scrollPane);
JPanel panel = new JPanel();
scrollPane.setViewportView(panel);
panel.setLayout(null);
JTextPane textPane_branding = new JTextPane();
textPane_branding.setBounds(98, 0, 78, 191);
panel.add(textPane_branding);
JTextPane textPane_trunk = new JTextPane();
textPane_trunk.setBounds(0, 0, 88, 191);
panel.add(textPane_trunk);
I'm not quite sure what you are trying to achieve here. If you want both of your JTextPane to be scrollable you need to put each one into its own JScrollPane. That would look like this:
JTextPane textPane_branding = new JTextPane();
JScrollPane scroll_branding = new JScrollPane(textPane_branding);
scroll_branding.setBounds(98, 0, 78, 191);
panel.add(scroll_branding);
JTextPane textPane_trunk = new JTextPane();
JScrollPane scroll_trunk = new JScrollPane(textPane_trunk);
scroll_trunk.setBounds(0, 0, 88, 191);
panel.add(scroll_trunk);
If you want both of your JTextPane being into one JPanel that is scrollable I'm wondering why you set fixed Bounds to your JScrollPane and to the JTextPanes. That makes Scrolling absurd here. And thats why JScrollPanes don't work with Panes that don't have Layouts and use fixed Bounds. Also it is very bad practise.
So I would suggest here to stay with a Layout Manager in your JPanel and use setPreferredSize with your JTextPanes to define your desired Dimensions. And then your JScrollPane will start working.
JScrollPane scrollPane = new JScrollPane();
//scrollPane.setBounds(402, 211, 178, 193); // Don't do this!
frame.getContentPane().add(scrollPane);
JPanel panel = new JPanel();
scrollPane.setViewportView(panel);
//panel.setLayout(null); // Use a Layout Manager
JTextPane textPane_branding = new JTextPane();
textPane_branding.setPreferredSize(new Dimension(78,191));
//textPane_branding.setBounds(98, 0, 78, 191);
panel.add(textPane_branding);
JTextPane textPane_trunk = new JTextPane();
textPane_trunk.setPreferredSize(new Dimension(88,191));
//textPane_trunk.setBounds(0, 0, 88, 191);
panel.add(textPane_trunk);
I'm trying to Refresh my data on JLabel Text.
My data on "mod.getAllPlaneteByUser(u).getQte_or()" get data from my DataBase.
The component "lblRefresh" is just a JLabel listener.
--> Initialization :
JLabel lblRessOr = new JLabel();
lblRessOr.setText(Integer.toString(mod.getAllPlaneteByUser(u).getQte_or()));
--> Add By default on my contentPane :
lblRessOr.setForeground(Color.RED);
lblRessOr.setFont(new Font("Lucida Grande", Font.BOLD, 16));
lblRessOr.setBounds(225, 141, 73, 16);
contentPane.add(lblRessOr);
--> Use on my MouseListener :
if(e.getSource() == lblRefresh){
lblRefresh.setText(Integer.toString(mod.getAllPlaneteByUser(u).getQte_or()));
lblRefresh.repaint();
}
Anybody know how i can refresh my data ?
If you are attempting to change the text in the lblRessOr Jlabel you would place the below code in your listener block.
if(e.getSource().equals(lblRefresh)){
lblRessOr.setText(Integer.toString(mod.getAllPlaneteByUser(u).getQte_or()));
}