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.
Related
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:
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.
Newbie to JavaFX here. I'm currently working on a JavaFX project. I somehow managed to create my main window with a text, a textfield and two buttons:
However, I have some trouble positionning a button where I exactly want it to be (the red-filled box)
Output example
Here's part of my launch method (only the code related to the buttons). Please note that grid is a private GridPane attribute.
this.grid = new GridPane();
this.grid.setPadding(new Insets(15));
this.grid.setVgap(2);
this.grid.setHgap(2);
this.grid.setAlignment(Pos.CENTER);
Button submitButton = new Button("Submit");
submitButton.setStyle("-fx-font: 20 arial; -fx-base: #b6e7c9; -fx-background-radius: 10, 10, 10, 10;");
submitButton.setBackground(new Background(new BackgroundFill(Color.LIGHTGREEN, null, null)));
Button exitButton = new Button("Exit");
exitButton.setTextFill(Color.RED);
exitButton.setStyle("-fx-font: 20 arial; -fx-base: #dbd8d6; -fx-background-radius: 10, 10, 10, 10;");
exitButton.setBackground(new Background(new BackgroundFill(Color.RED, null, null)));
this.grid.add(submitButton, 0, 2);
this.grid.add(exitButton, 1, 2);
How can I manage to align the Exit button more to the left, to be symetrical with the Submit button, i.e. just under the TextField?
I really appreciate your help.
EDIT1:
The question (Text) is at 0,0. The TextField is at 0,1.
EDIT2
Code for Text and TextField:
TextField answer = new TextField();
answer.autosize();
this.answer = answer.getText();
this.grid.add(answer, 0, 1);
Text question = new Text("Hi there ! Press Submit to start! Exit to quit.");
question.setFont(Font.font("Century Gothic", FontWeight.BOLD, 22));
question.setFill(Color.BLACK);
this.grid.add(question, 0, 0);
Make the text and text field span two columns:
TextField answer = new TextField();
answer.autosize();
this.answer = answer.getText();
// node, columnIndex, rowIndex, columnSpan, rowSpan:
this.grid.add(answer, 0, 1, 2, 1);
Text question = new Text("Hi there ! Press Submit to start! Exit to quit.");
question.setFont(Font.font("Century Gothic", FontWeight.BOLD, 22));
question.setFill(Color.BLACK);
this.grid.add(question, 0, 0, 2, 1);
and then make the "Exit" button right-aligned, and it should work the way you want:
this.grid.add(submitButton, 0, 2);
this.grid.add(exitButton, 1, 2);
GridPane.setHalignment(exitButton, HPos.RIGHT);
I so have made a GUI for a Chat that im currently working on. Its aaaaalmost done but the only thing is the automatically resizing when dragging the window. I can't find out why its happend and this was my last chance. So I really need help from you guys! Im kinda out of idea
The code is here:
ClientGUI(String host, int port) {
super("Chat Client");
defaultPort = port;
defaultHost = host;
// The CenterPanel which is the chat room
MessageText = new JTextArea("Welcome to the Chat room\n");
JPanel centerPanel = new JPanel();
MessageText.setWrapStyleWord(true);
MessageText.setLineWrap(true);
centerPanel.setLayout(null);
JScrollPane scrollPane = new JScrollPane(MessageText);
scrollPane.setBounds(0, 0, 584, 486);
getContentPane().add(scrollPane);
MessageText.setEditable(false);
getContentPane().add(centerPanel, BorderLayout.CENTER);
WriteMessage = new JTextField("Write your username here!");
WriteMessage.setBounds(0, 492, 584, 35);
centerPanel.add(WriteMessage);
WriteMessage.setColumns(234);
WriteMessage.setBackground(Color.WHITE);
// the 3 buttons
Login = new JButton("Login");
Login.setBounds(594, 338, 125, 35);
centerPanel.add(Login);
Logout = new JButton("Logout");
Logout.setBounds(594, 469, 125, 35);
centerPanel.add(Logout);
Logout.addActionListener(this);
Logout.setEnabled(false); // you have to login before being able to logout
Online = new JButton("Online");
Online.setBounds(594, 403, 125, 35);
centerPanel.add(Online);
Online.addActionListener(this);
Online.setEnabled(false); // you have to login before being able to Who is in
JLabel PortNumberText = new JLabel("Port Number: ");
PortNumberText.setBounds(594, 83, 144, 20);
centerPanel.add(PortNumberText);
PortNumber = new JTextField("" + port);
PortNumber.setBounds(594, 114, 129, 20);
centerPanel.add(PortNumber);
PortNumber.setHorizontalAlignment(SwingConstants.RIGHT);
JLabel ServerText = new JLabel("Server Address: ");
ServerText.setBounds(594, 21, 240, 20);
centerPanel.add(ServerText);
// the two JTextField with default value for server address and port number
ServerAddress = new JTextField(host);
ServerAddress.setBounds(594, 52, 129, 20);
centerPanel.add(ServerAddress);
Login.addActionListener(this);
WriteMessage.requestFocus();
setDefaultCloseOperation(EXIT_ON_CLOSE);
setSize(760, 570);
setVisible(true);
}
A picture what I mean
Don't use a null layout. Don't use setBounds(). Swing was designed to be used with layout managers.
Resizing of components can only be done when you use a layout manager. Read the section from the Swing tutorial on Layout Manager for more information and examples. You can always use multiple panels each with a different layout manager to get your desired results.
Also follow Java naming conventions. Variable names should NOT start with an upper case character. Half the time your names are correct and half the time they are not. Be consistent!
You are using a Null-Layout (absolute positioning), and this means you have to take care of everything related to layout yourself. Better use a LayoutManager.
Alright so I just made a border layout all from start so I guess its all good, Thanks everyone for helping! Doesnt look that professional. So yeah, Might be some more updates later on :)
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()));
}