FAQ Database Discussion Community


Screen flickers when setting background

java,swing,double,buffer,flicker
I'm trying to make a simple GUI program without using JComponents. Currently, I have a BufferedImage that I draw to off screen so that it doesn't flicker (or so I thought). I made a new program here to replicate the issue: package Main; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import...

Search Icon inside a Editable JComboBox / JTextField

java,swing,jcombobox
I have an Editable JComboBox search field in one of my Java swing application. I wanted to save space of the search box header and put in search icon inside the editable jcombobox to depict it as a search field. Which should look quite similar to a Facebook search...

Calling a java class from a parent directory

java,swing,miglayout
I have two java classes SortsGui.java import javax.swing.*; import java.awt.*; import net.miginfocom.swing.MigLayout; import Sorts.*; import javax.swing.event.*; import java.awt.event.*; public class SortsGui { JFrame myMainWindow = new JFrame("Sorts"); JPanel sortPanel = new JPanel(); MyMenuBar mbr = new MyMenuBar(); //first panel components JTextField txtField = new JTextField(); JTextField txtField2 = new JTextField();...

Why JavaFX requires Platform.runLater to change anything in it's UI inside a thread?

java,multithreading,swing,javafx
This code of a simple swing application: final JFrame jFrame = new JFrame(); final JLabel jLabel = new JLabel("Test"); jFrame.add(jLabel); jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); jFrame.pack(); jFrame.setLocationRelativeTo(null); jFrame.setVisible(true); Thread thread = new Thread(){ @Override public void run() { while(true) { jLabel.setText("Time: " + System.currentTimeMillis()); try { Thread.sleep(1000);} catch(Exception ex) {} } } }; thread.setDaemon(true);...

dispose() vs setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

java,swing
I have been searching around quite a bit about this topic but never got any satisfaction about any answers so ended up asking a question here :). Anyways, from this similar post it was clear that dispose() does not terminate all the processes and still has remains in the...

Image as a background in JScrollPane

java,image,swing,background,jscrollpane
How to add an image as a background in JScrollPane? I tried this but the image doesn't display: BufferedImage img = null; try { img = ImageIO.read(new File("C:\\Users\\Suraj\\Documents\\NetBeansProjects\\JavaApplication2\\src\\javaapplication2\\images\\2.jpg")); } catch (IOException e) { e.printStackTrace(); } Image imag = img.getScaledInstance(d.width, d.height, Image.SCALE_SMOOTH); ImageIcon imageBack = new ImageIcon(imag); FlowLayout fl = new...

Putting text from JTextField to JLabel

java,swing,jlabel,jtextfield
I 'm working on code that takes a string from a JTextField and puts it on a JLabel. But my problem is always the string shown is missing the last character. private void jTextField1KeyTyped(java.awt.event.KeyEvent evt) { String ch=jTextField1.getText(); jLabel1.setText(ch); } ...

Display attribute in JComboBox and register another attribute

java,swing,jdbc
I have a JComboBox and I must show the designation of the product, and each has a code designation, in my database I have to register the product code but in the Combo I must show the designation, how should I do to display the designation in the combo but...

AbstractTabelModel won't show the JTable collumn names

java,swing,jtable,abstracttablemodel
For some reason my JTable is not displaying it's column names?! I'm certain I've done everything correctly. I've literally copied this from a demonstration so i don't understand why it won't work. Here is my code: public class MemTableModel extends AbstractTableModel{ private ArrayList<member> members = new ArrayList<member>(); private String[] columnNames...

Importing text into a JTable is not displaying

java,swing,jtable,jtextfield
I have created a program where I can input data in JTextField and on hitting save button I use a JFileChooser to save the data in a .txt file where each JTextField is in a new line. I also created a button that pops up a JFileChooser to browse for...

Can you make an editable label?

java,swing,jlabel
Quick question, can you make a textfield, that looks like a JLabel, but that can still be edited? You could still change its size and its font, but the background + the border should be gone. As of now, I'm trying to do this with Swing. What you would still...

Array JLabel ActionListener multiple JPanels

java,arrays,swing
I have an array of JLabels and I want to add an ActionListener to them. Every label should display a panel and the other should be removed. How can I realize this?

Unable to get each item from selected multiple line Jlist?

java,swing,jlist,defaultlistmodel,listcellrenderer
After doing lots of research i am still unable to get items from selected multiple line jlist. Here is my code for listSelectionListener: list.addListSelectionListener(new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { ListModel model = list.getModel(); for(int i=0; i < model.getSize(); i++){ System.out.println( model.getElementAt(i)); } } }); I also added a...

Adding items to combo box in a table in netbeans

java,swing,netbeans,jtable,jcombobox
I have a table and one of its columns needs to contain combo boxes. When I run the following code, I get combo boxes in each cell but the items are not added into it. When I try to print the items using system.out.println(val), they get printed but they do...

Focus on the button using tab key and press enter

java,swing,netbeans,jbutton,actionlistener
I have a simple jFrame with a submit button and a cancel button. Currently, everything works perfectly. User perform action on mouse click. Now I want to press 'tab' first to focus the button then it should fire whenever someone presses the enter key. It should work for both keys....

Java MySQL and JFrame connection “Cannot convert from boolean to connection”

java,android,mysql,swing,import
public class BancoDeDados { static String url = "jdbc:mysql://localhost:3306/Estoque"; static String pass = "admin"; static String user = "admin"; static Connection conexao = null; public static boolean conecta() throws ClassNotFoundException { try { Class.forName("mysql.Driver"); conexao = DriverManager.getConnection(url, user, pass); //System.out.println("Conectado."); JOptionPane.showMessageDialog(null, "Conectado com Sucesso!"); return true; } catch (SQLException e)...

image doesnt shows on JLabel when click on next button, using java Swing

java,swing,jlabel,imageicon
I am trying to make small program that shows pic on JLabel when user click on Next Button.The Problem is when i click on next button it shows nothing.but if i resize frame it shows all pics from directory. instead of one picture at a time. Please excuse my English....

how to refresh JFrame after after adding java 2d components

java,swing,graphics,graphics2d
in this code i added two components to the jframe and also used revalidate and repaint but only one of the components is being viewed. i need a way to refresh the jframe class A extends JPanel{ int i ,j; A(int i,int j){ this.i = i; this.j = j; }...

Coloring Text in JTable Cell

java,regex,swing,jtable,tablecellrenderer
I want to color text in a JTable cell. I'm using a DefaultTableCellRender with HTML Tags to color multible words/text. I'm using Regex to find words/text and replacing them by adding HTML Tags. The problem here is that the HTML tags them selves should not match by the regex. example:...

JCheckBoxes not being disabled after I setEnable(false) them

java,swing,checkbox,jframe,enable-if
If have 30 checkboxes and I don't want more than 6 of them to be checked. I have an int keeping track of how many are checked. Each box has an item listener which calls a method to see what that int is at, and if it reaches 6, the...

How to prevent memory leak in JTextPane.setCaretPosition(int)?

java,swing,memory-leaks,jtextpane,caret
I'm working on a Java application with Swing-based GUI. The application uses JTextPane to output log messages as follows: 1) truncate existing text to keep total text size under the limit; 2) append new text; 3) scroll to the end (actual logic is slightly different, but it's irrelevant here). I...

JButton ActionListener not responding

java,swing,jbutton
I couldn't find the answer anywhere else online, so I came here. I apologize in advance if the mistake in my code is very obvious; I'm still quite new to java swing. Here's what's going on: I have created a JButton named toggleElevators, and I want it to change text...

Java: What Layout Manager would be best for a game menu?

java,swing,layout-manager
=================== Game Name Play Exit =================== the above is what my previous game menu looked like. I used the Box Layout to create it but it was very tedious. Is there there a better layout manager that I could use? here is the code for those that asked of the...

JFrame not adding graphics from separate class

java,swing
I'm quite new to swing, and I'm having an issue with graphics not showing up in my JFrame. What I should be seeing is a blue rectangle slowly moving downwards through the frame, and behind it is a plain white background. However, when I run my main class, all I...

JButton toggle method not working as expected

java,swing,user-interface,jbutton
Here's what I'm trying to do: Create a JButton, and when clicked, its setText() will change to Happy, and then when clicked again, its setText() will change to Sad. Basically, I want it to toggle between Happy and Sad when clicked. (Sorry for the awful explanation) The issue is that...

Why this indeterminate jProgressBar don't work in this simple code?

java,swing,concurrency,process,jprogressbar
I want use an indeterminate jProgressBar on a JForm but I don't know why in my code don't work. The jProgressBar must be in the indeterminate status until the thread receives a latch.await() signal. This is the simple part of code when I push a button: private void jButton5ActionPerformed(java.awt.event.ActionEvent evt)...

populate a 'JTable' with values from a '.txt' file

java,swing,file-io,jtable,stringtokenizer
I'm new to java and I have a text file like this 0786160384|P. K.|Tharindu|912921549v|Colombo| 0711495765|P. K.|Gamini|657414589v|Colombo| 0114756199|H. P.|Weerasigha|657895478v|Kandy| I want to populate my 'jTable' with with the data from this text file. below is my code so far which doesn't work. When I execute the program nothing is displayed on...

JButton listener not firing

java,swing,button,actionlistener
I seperated my codes into MVC model and now my confirm button action listener is not printing the username and password even though I added a Actionlistener for it. please help thanks. Codes LoginDialog.java import java.awt.BorderLayout; import java.awt.FlowLayout; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JDialog;...

JPanel Black screen because of componentResize and long repaint command

java,swing
The problem is obvious: I have a big paint command with a very large for loop and a componentResized that runs the paint command a huge amount of time, which makes my JPanel a black screen and unable to exit even when I press the x button(I must terminate it...

Why is java.awt.Graphics.drawLine exceptionally slow?

java,swing,graphics2d
I am trying to achieve the following 'grid' layout. The class is extending java.awt.Canvas, and drawing these shapes (or lines) in the paint function. Why Canvas? Check here, trying to do something similar inititally. Updated MCVE Code for getting the above 'layout': import java.awt.BasicStroke; import java.awt.BorderLayout; import java.awt.Canvas; import java.awt.Color;...

Recognizing Blocked Swing EDT

java,multithreading,swing
How to know that EDT is blocked (not visually but by inspecting the thread itself)? is there a way? I'm on the way to my final university task for graduation that have bunch of charts , but have little knowledge of Swing EDT (Java generally). have look at this piece:...

(Java)How to change picture(War Card Game)

java,swing,user-interface,war,playing-cards
Ok what im trying to do is make a image called hidden and it will be a card face down. Now I want to make it so the image will change to a face up card and what i tried to do was make a image for six cards three...

I am able to capture the TAB in a jtable, but how do I capture the SHIFT+TAB?

java,swing,key-bindings,key-events
I have a JTable that I need to change the traversal inside such that a TAB keystroke advances row by row. (Normally, the TAB keystroke advances cell by cell.) I was able to change the forward traversal on the TAB keystroke. I tried the same thing for reverse traversal on...

Repaint Table issue with Swing JTable

java,swing,jtable
I am working with swing JTable and have a trouble with repainting table. I draw a JTable with thr following code Object[] column = new Object[]{"Entity", "Attribute"}; Object[][] rowData = new Object[][]{{"E1", "A1"},{"E2", "A2"}}; TableCellRenderer cellRenderer = new TableCellRenderer(); JTable table = new JTable(new DefaultTableModel(rowData, column)); table.setCellSelectionEnabled(true); table.getColumnModel().getColumn(0).setCellRenderer(cellRenderer); Below is...

How to show Data in JLabel and Jext Boxes java swing dynamically from properties file Without knowing data in properties file

java,swing,properties,core
Ii am working on a module of java swing in which i want to return data into java swing textboxes and labels. The text boxes and JLabel should be varies dynamically according to data retrieve and I don't know about the properties name and their values...but i have to retrieve...

Dynamic width and fixed height of rows in JPanel

java,swing,jpanel,jscrollpane,layout-manager
I am trying to use Java layout managers (I have no external libraries, and am using Java 7) to create a layout where data is provided in rows, where the rows have a fixed height, but the width fills to fit the window. An example is provided below: The idea...

Making a chess game in Java, I want to move the pieces

java,swing,jbutton,imageicon,chess
So I have my images stored as ImageIcon's on JButtons. I want the user to click on the JButton of the piece they want to use and then click on another JButton to move it there, how would I do this? I've tried using an actionListener to get the ImageIcon...

Calling a JMenuBar from another class

java,swing,jframe,jmenubar
I have the following code for a GUI with a button on it and code for a JMenuBar. MenuBarTest.java import javax.swing.*; import java.awt.*; import java.awt.event.*; import MenuBar.*; public class MenuBarTest extends JFrame implements ActionListener { JFrame myMainWindow = new JFrame("This is my title"); JPanel firstPanel = new JPanel(); JButton btnTest...

JFrame.repaint() and JFrame.revalidate() not working

java,swing
import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.KeyListener; public class TheSize extends JFrame implements ActionListener, KeyListener { static String inText=""; JPanel pane=new JPanel(); JLabel word0=new JLabel("I would like my grid to be 2^",JLabel.RIGHT); JLabel word1=new JLabel("* 2^ "+inText,JLabel.RIGHT); JButton finish=new JButton("I'm done"); JTextField size=new JTextField("",3); public...

Buttons and paint method

java,swing,graphics,jbutton,actionlistener
I'm having trouble with my buttons. I know they're working because I've tested them out by exiting the problem through System.exit. Here is what my output looks like: http://imgur.com/Ks7mIFa When I click the close button, the handle on the switch should redraw to the other side and the close button...

JRadioButtons before every line

java,swing,joptionpane,jradiobutton
I have this program that reads questions with multiple choice answers from a text file and then displays a random set of them in a JOptionPane (very question in a new Pane). In my text file the questions and the 4 options of answers are all in one line and...

Java: Add Place Holder on JTextField

java,swing,jtextfield,prompt
Guys is there a way or method in which we can add placeholder in j text field.I want to add placeholder "Enter Your Number" in field but how can i do this.I check all methods but didn't working. Code: public class Loop extends JFrame{ private JTextField t1; public L(){ getContentPane().setLayout(null);...

JFrame wrong location with Ubuntu (Unity ?)

java,swing,ubuntu,jframe,location
It seems that there is a bug with Ubuntu (maybe only unity). The decoration of the JFrame is taken into account for getLocation() and getSize(), but not for setLocation() and setSize(). This leads to weird behaviour. For instance, if you use pack() after the frame is displayed and the dimensions...

JFrame popup not showing content [on hold]

java,swing,jframe,event-dispatch-thread
I have ClassA that does some processing and I want it to create a popup Jframe ClassB that shows some statistics that ClassA calculated. So I did something like this: public class MainMenu extends javax.swing.JFrame { public MainMenu() { initComponents(); } private void initComponents() { calculateButton = new javax.swing.JButton(); setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);...

java null pointer exception JMenuBar [duplicate]

java,eclipse,swing,user-interface,nullpointerexception
This question already has an answer here: What is a Null Pointer Exception, and how do I fix it? 12 answers Im stuck today with a java error on an eclipse 3.8 platform. I try to generate a simple MenuBar on a JFrame. The JMenuBar contains the JMenu("Help") and...

How To Initialize a JComboBox Whose Items are added Dynamically?

java,swing,jcombobox
I have Created a JComboBox and its item are being added dynamically through a LinkedList, how to initialize its selected value. Suppose "list" contains A->B->C->D->null I want to intialize the ComboBox selected index with B (i.e 2nd Item In the list). I have tried to do it as below ComboBox.setSelectedIndex(1);...

Why textPane.getDocument().getText() Returns Empty String?

java,swing,jtextpane
What am I doing wrong here in an attempt to get text (with newline characters at their places) from a JTextPane component with content-type "text/html"? textPane.getText() returns HTML but with empty head and body. textPane.getDocument().getText() returns an empty string. P.S.: I am also having no line-wrap and other issues in...

Animation not adding to JFrame

java,swing,graphics
I'm new to java swing, so forgive me if my mistake is extremely obvious. What my code is supposed to do here is create one JFrame and animate two boxes moving upwards through the frame side by side. However, I'm seeing only one box (the blue box created by the...

Syncing a JTable with ArrayList of Objects values in Java

java,swing,arraylist,jtable
My program has a JTable which displays information about a student. e.g. Columns contain: "Name", "Surname", "Age", "Year" I also have an Object class for students as follow: public class Student { private final String name; private final String surname; private final int age; private int year; public Student(String name,...

Adding a scroll pane to GridBagLayout

java,swing,jtable,jscrollpane,gridbaglayout
I am trying to add two scroll pane along with one label and one button in a JPanel using GridBagLayout. While the first scroll pane containing a JList and the second scroll pane containing a JTable. Below is the code: JPanel capabilityPanel = new JPanel(new GridBagLayout()); GridBagConstraints constraints = new...

How to move JFrame shape

java,swing,animation,awt,java-2d
I'm trying to develop a simple game. The games is about the shapes. Shapes will move and we'll catch by mouse. I have already created a oval and given size of oval graphic. But I cannot move this shape repeatedly. I think I need to use timer class. I have...

Prevent breaking of JTextField / JDialog with repeated transferFocus()

java,swing,jtextfield,jdialog
I have a very strange scenario which unfortunately I cannot prevent from occurring in my Swing application. When it occurs however, it has major consequences for me. Perhaps somebody could help! The basic setup is as follows: Linux environment. Multiple JTextFields in a JFrame. JTextFields push through transferFocus() when the...

Last image on JLabel is shown for all after adding JLayeredPane in loop

java,swing,bufferedimage
Sorry for the bad title, could not think of anything better. I am building a card game. The below method takes a Card object as argument and returns me a JLayeredPane with a JLabel having the image for the card. private JLayeredPane getCardPane(Card card) { JLayeredPane cardPane = new JLayeredPane();...

Clojure invokeLater null pointer

swing,concurrency,clojure
This code: (import 'javax.swing.SwingUtilities) (SwingUtilities/invokeLater (print "hi")) Causes this error: Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at java.awt.event.InvocationEvent.dispatch(InvocationEvent.java:209) ... I don't know if this is a problem, since the code itself actually works (printing to the REPL) despite the error. However, modifying swing components does not seem to work properly: a...

“Terminal” font used in Paint for Windows 8 [closed]

java,swing,fonts
I want to use the Terminal font that I've been using for a few headers I made in Paint. I know that Java doesn't support bitmap fonts. I'm trying to find a way to get a TrueType version of the above font and I'm getting absolutely nowhere. The last resort...

JTable not updating values as new rows are added

java,swing,jtable
This is the screen of my system where it lists the available Magazines("revistas") and Books("livros") from ArrayLists of String[] containing Name,Availability,Code. Everything is working fine, except the table is showing blank. This is my class, I've cropped the variable declarations. Function "listar" at the bottom is what loads the JTable...

MigLayout, aligning all components at center of JFrame

java,swing,miglayout
how can I align my components at JPanel at the center of JFrame. Here are my codes and what i got I want like this MainFrame import javax.swing.JFrame; import javax.swing.JPanel; public class MainFrame extends JFrame { private static MainFrame instance = new MainFrame(); public static MainFrame getInstance() { return instance;...

Updating jTextArea in while loop

java,swing,while-loop,jtextarea,updating
I am having a problem writing/updating the textarea. I am getting a value from the readtemp function, and i can see the result after calling the system out function, but nothing appears in the Textarea. What could be the problem? private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { URL temp; try { temp...

Custom JComponent to set preferred scrollable viewport size

java,swing,jscrollpane,preferredsize,jviewport
So I am trying to create a custom component so I can set the size of my scroll pane. Here is the part with the scroll pane: JScrollPane scrollPane = new JScrollPane(leftTop); customScroll t1 = new customScroll(); scrollPane.add(t1); left.add(scrollPane); leftTop is a nested panel inside of left. Here is my...

Java: how to access the parent JFrame's methods within the Jpanel [on hold]

java,swing
my JFrame and JPanel are two separate classes, my JFrame uses the JPanel as its own content pane. Inside the JPanel, when a certain button is clicked I want to set the visibility of the JFrame to false. I don't get how to access the JFrame's methods within the JPanel...

empty JTextField and adding number

java,swing,error-handling
I have three JTextfields called vol1HH1,vol1HH2,vol1HH3 and fvol. The result of which is output after an actionPerformed event. A user may just input a numbers into vol1HH1 and vol1HH2 but not vol1HH3, how would i ensure that the two numbers were added and the result displayed into fvol without causing...

I cannot close JFrame

java,swing,dispose
I have two java forms: NewJFrame i NewJFrame1. I have button on NewJFrame, so when I click on that button to open NewJFrame1 and close NewJFrame. It can open NewJFrame1, but it cannot close NewJFrame. This: NewJFrame frame = new NewJframe(); frame.setVisible(false); doesn't work. Also, frame.dispose(); doesnt work. CAn someone...

jtable returns only one row from the database

java,mysql,swing
i want the table to return the data from database without specifying the number of rows, i used the autoincrement in the default tablemodel but it doesnnot display all the rows, i have to define the table outside the actionlistener so as to add it to a JPanel,so the problem...

How can I implement a Zoom Panel with Java Swing libraries

java,swing,dictionary,scrollbar,zoom
I've implemented a JFrame with Java Swing libraries to visualize a map. I'd like to realize a zoom function within this frame. This is the code of my JFrame: package components; import java.awt.BorderLayout; import java.awt.Container; import javax.swing.JFrame; import javax.swing.JScrollPane; public class MyFrame extends JFrame { private static final long serialVersionUID...

I want to make a dockable frame In java Swing Desktop application [closed]

java,swing
I am new in java technology, so not enough idea to how start this application or you can say that is any extra configuration or jar required or it make as simple desktop swing application.

Referencing from an inner class

java,arrays,swing,keylistener,miglayout
I have the following code import javax.swing.*; import java.awt.*; import net.miginfocom.swing.MigLayout; import Sorts.*; import javax.swing.event.*; import java.awt.event.*; import java.awt.Color; public class SortsGui { JFrame myMainWindow = new JFrame("Sorts"); JPanel sortPanel = new JPanel(); //first panel components public int nextTextBox = 20; JTextField[] allField = new JTextField [25]; //end first panel...

How to open a JFrame that was previously hidden from another class?

java,swing,jframe,instances
I have 2 frames and in the first one, I press a button to go to the other and then I hide the frame with: frame1.this.hide(); How can I set that frame visible without creating a new one? I know that I can make an instance to open a new...

Text in JLabel doesn't get updated on pressing a JButton

java,swing,jlabel
I am working on a project but the program seems to have a bug that I can not find. Here is an MCVE which reproduces the problem: import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.JButton; import java.awt.FlowLayout; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class SO{ JLabel label; JButton button; JPanel panel;...

Manipulating components in a separate class java

java,swing,miglayout
I have three java classes StitchSorts import Sorts.*; public class StitchSorts { public static void main(String[] args) { StitchSorts sS = new StitchSorts(); SortsGui.main(args); } } SortsGui package Sorts; import javax.swing.*; import java.awt.*; import net.miginfocom.swing.MigLayout; import Sorts.*; import javax.swing.event.*; import java.awt.event.*; public class SortsGui { JFrame myMainWindow = new JFrame("Sorts");...

how to get name of a accessible parent(panel) in swing?

java,swing,parent-child
When i click the button, it will print the accessible parent name. is there any way is to do that?. I have tried some codes, but its printing null. Can anyone point out my mistake. Container c = cancel.getParent(); System.out.println("Parent Name = "+c.getName()); ...

How set size of specified String to JTextField?

java,swing,layout-manager
JTextField in JPanel which in turn in JDialog doesn't take specified size. I tried to use BoxLayout and FlowLayout, but still have not achieved the desired size. I.E. I measure the size of String example and set this size to width of JTextField inputCat, but inputCat doesn't take this size,...

Java - Applet to Executable Jar Wrapping

java,swing,applet,jframe,jpanel
I have written a Java XML Parser as an Applet. It is looking and functioning well enough in this form. My Question, Is if I want to run this without a browser, how Would I properly wrap it to run as an executable? GUI.java -------------- import java.applet.*; import java.awt.*; import...

trouble with GridBagLayout and panels

java,swing,layout,layout-manager
So what I am trying to do is create this: I am using a gridbag layout and here is what I have so far: public class board { public static void addComponentsToPane(Container pane) { pane.setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); JPanel leftTop = new JPanel(); leftTop.setPreferredSize(new Dimension(251,300)); leftTop.setBackground(Color.black); c.fill...

Accessing an object created by a constructor

java,swing,jframe
I'm trying to learn some basic GUI implementation in Java. I have 2 classes, one which contains a constructor. This constructor creates a new JFrame object. I'm having trouble with working with this JFrame constructor - I want to change its size, and other operations, but can't figure out how...

Java JButton.setAction(…) null's button text

java,swing,jbutton,action
The following code renders a JButton without text: public abstract class Test { public static void main(String... args) { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) { e.printStackTrace(); } SwingUtilities.invokeLater(() -> { JFrame frame = new JFrame(); JPanel panel = new JPanel(); String text...

Java Swing JFrame launch another JFrame for game

java,swing,event-dispatch-thread
I am developping a little game using Java. I have a main JFrame for my application that can create another Window (the game window) by clicking on a JButton. I have already teste my game window alone and everything is ok. Here is my game window constructor: public GameWindow(final GameController...

Errors trying to add rectangles to JPanel

java,swing,debugging,graphics
I am trying to draw a grid of rectangles on a JPanel that already has a few JButtons on it. I get a big list of errors when I try to run it. Here's my code: package GameOfLife; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.*;...

Unable to read data from JTable editable cell

java,swing,jtable
I am directly inserting data into JTable, suppose there are 5 rows in JTable and I inserted values in all and in last I am inserting value in a cell of fifth row, and cell is in editable mode, in this situation I cant read data from that cell.

Validation of text fields and contact no text field

java,swing,validation,textfield
I have a JFrame consisting of some text fields (10) and a TextArea. I want to validate all the text fields and see if they are not empty and also check if a 10 digit contact no is entered in one of the text field. After checking the text fields,...

Want to create a frame taking mouse input and implements drawLines()

java,swing
I am trying to create a frame that is taking input from mouse and also make x/o grid on frame using drawLines(). But I am able to do only one of the two. Here is my code: public class Test extends JPanel { public static void main(String[] args) { Test...

Implementing JOptionPane in Java

java,swing,joptionpane
I created this popup window which will show up in response to a button being clicked in my gui. I have two questions regarding this. How do I get rid of the text field below the radio buttons? I need to check which radio button was selected once the ok...

How to pass JTextField from JFrame into another JFrame?

java,swing,jtextfield
I have two JFrame (JFrame1 and JFrame2) with two JTextField1 and JTextField2. My question is when I write "Hello world " on JTextField2 from Jframe2 and then click on OK button, I see "Hello world " on JTextField1 on Jframe1 class. How can I do this? I'm sorry if this...

How to add system time(running) to a Jpanel?

java,multithreading,swing
I am quite new to java coding. So don't know much of it. I am trying to add system clock(running) to my frame. I am using a jpanel to do so. Here is my code, import javax.swing.*; import java.util.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; public class Emp_Try implements ActionListener,...

java Swing: how to keep one component left aligned with another component centered with respect to parent

java,swing,layout,jpanel,layout-manager
Say I have two components, A and B, in a JPanel. I want Component A to stay left aligned, while Component B does its best to stay in the middle of the panel. I mocked up the following demo (sorry for the quality, I made it in paint): What I...

Why doesn't my JFrame repaint when I set a new Synthetica theme?

java,swing,jframe,themes,synthetica
I just set my applications theme to Synthetica Alu Oxide but some reason the JFrame doesn't repaint but another Synthetica theme will repaint the JFrame. This is what mine looks like. http://i.imgur.com/SOBDTs4.png This is what its suppose to look like. http://www.jyloo.com/images/screenshots/syntheticaAluOxide/democenter2.png public MainPanel() { JFrame frame = new JFrame(); frame.setTitle("Asteria...

JFileChooser select just directories

java,swing,jfilechooser
I am using JFileChooser to allow the user of my application to select a directory for file storage. Per the documentation and other StackOverflow questions I have researched I have added this bit of code: fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); Doing this does return the directory that I need, but to select that directory...

Adding JPanels to JScrollPane

java,swing
I'm trying to show multiple smaller JPanel on a JScrollPane. To achieve this I currently add them to another JPanel and set this panel as the ViewportView of the scrollPane. Is there a way to add the panels directly to the scrollpane? What didn't work is this: JScrollPane scrollPane =...

Setting font in JOptionPane without using HTML

java,swing,fonts,joptionpane
I tried this: Code Zip Sorry for the inconvenience but I could not attach the whole code (though it's not too big) and could not provide .java extension link so you have to get the zip and it open in html where code is with syntax highlighting. I read these:...

addActionLister parameter

java,swing,event-handling,awt
I am getting expected output when i am using "this" reference in addActionListener() call, how can I achieve it using the object call directly ? When i am using jb.addActionListener(new EventHandling1()); I am getting error -"Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException". Also which object needs to be passed to this method...

How to highlight all the occurrence of a particular string in a web page?

java,html,string,swing
I am writing a swing application. In this application there is a table with some HTTP links. When I click a row a new browser window opens. To this point everything works good. Now I would like to know if it is possible to have all the occurrences of a...

Keystroke/Hot Key for JButton in Java

java,swing,jbutton,hotkeys,jmenu
Initially I was using JMenu and establishing hot keys to work using accelerator. It was working perfectly. Now I want the same behavior in JButton but I am stuck. Here is the code that I wrote : Please share your ideas so I can go in the right path. import...

How can I make an entire row have a border when a cell in the row receives focus?

java,swing,jtable,focus
I have a JTable with 4 columns. Each column has it's own customized cell renderer. When a cell receives the focus, it gets a border around it. How can I make the entire row have a border and not just one cell?

Why isn't this program repainting a certain part of an applet even when repaint() is called

java,swing,applet,label,repaint
This is a simple rock, paper, scissors appelet. there are 3 variables keeping track of wins, losses, and ties. Then there is a label that is meant to display them. When I used the debugger the repaint method is being called so I don't understand why this portion of the...

Own Coordinates for JPanels

java,swing,jpanel
Code: for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { JPanel panel = new JPanel(); addListener(panel); panel.setBorder(new LineBorder(Color.black,1)); grid.add(panel); - public void addListener(JPanel p) { p.addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { System.out.println(panelX); System.out.println(panelY); } }); How can I set a X-coordinate and a Y-coordinate for each panel? (If i = 5...

How to Update JFrame Components?

java,swing,jframe,refresh,listener
Well, i have this code. import java.awt.EventQueue; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.ImageIcon; import javax.swing.SwingConstants; import javax.swing.JProgressBar; import javax.swing.SwingUtilities; import java.awt.Font; import javax.swing.JSeparator; import javax.swing.JTextPane; import javax.swing.JButton; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; public class Menu { private JFrame frmFelps; /** * Launch the application. */ public static void main(String[] args) {...

Custom JPanel causing rendering problems in second custom JPanel

java,swing,jpanel,paintcomponent
Bit of an odd one here. I have two classes extending from JPanel, overriding paintComponent in both. One implements Runnable (for animation purposes). However, when used together with the Runnable one on top, I get the wonderful "paint a copy of everything the mouse points at" in the background of...

How to keep GridBagLayout from changing the size of a button

java,swing,user-interface,layout-manager
In my FlashCardPanel class, I have a subpanel,LabelPanel, with a Grid Bag Layout. It consists of a constructor with an edit button, a button to "flip" the card, and the label to display the term/definition. My problem is that every time I click my "Flip" Button to display the definition...

How to draw 2d arrows with Java Swing?

java,swing,paintcomponent,arrow,jslider
I'm trying to draw some rotatable arrows with Swing 2d, there are some sample code online, so I copied and combined them into one app, but there is something wrong with each of the 3 methods : 1st one doesn't rotate from it's center, the other 2 don't look correctly...

Display captcha in Jframe

java,swing
I want to create application for registration in Java, then I want to submit the information to a website. This is only experiment so the information for the registration(e.g username, password) will be submit with GET request. However I want to integrate captcha with the registration and I want to...

Passing “this” as a Method Argument - Clarification

java,swing,methods,this,actionlistener
I am currently working on Java Swing lessons after finishing my first set of lessons in Java. In this lesson, we are working on communication between different components (buttons,toolbars,etc.) that we have been studying. The problem is, "this" is being passed as a method argument for the addActionListener() method. This...