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);
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.
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 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 :)
Goodevening
how can have a JTextArea like in netbeans (see the pic)
(source: hostingpics.net)
my code of the JTextArea:
JTextArea infoArea = new JTextArea(10,10);
infoArea.setLineWrap(true);
infoArea.setFont(police);
infoArea.setForeground(Color.YELLOW);
infoArea.setBackground(Color.BLACK);
infoArea.setEditable(false);
JScrollPane scroll = new JScrollPane(infoArea);
scroll.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
scroll.setBorder(BorderFactory.createEmptyBorder(5, 0, 10, 0));
scroll.setPreferredSize(new Dimension(sousFrame.getWidth(),90));
scroll.setFont( new Font("Arial", Font.BOLD, 13));
scroll.setBorder(BorderFactory.createTitledBorder("Output"));
thank you
I'm not sure what NetBeans uses, but we used flexdock at my last company to create dockable windows in a Java Swing application (assuming this is what you meant by "retractable").