Hello, I would like to develop a sprite editor. Therefore I have programmed a software like paint. As you can see on the picture, on the right, there is a canvas with a grid on it. I use a GridBagLayout to manage every widgets inside my window. The canvas is represented by a JLabel which is inside a JLayeredPane. I have set the size of the JPanel with setPreferredSize. It works well with my screen resolution because there is enough space to display the canvas. However on smaller screen, it doesn't show up. Any idea on how to adapt the …

Member Avatar
Member Avatar
+0 forum 1

In my Food Tab, I wanted to achieve this [Click Here](https://sfault-image.b0.upaiyun.com/358/064/3580648794-597611aa1f701) But I only able to get this [Click Here](https://sfault-image.b0.upaiyun.com/779/111/779111227-5976120f6955a) How can I increase the width of the JTextField which are in Food Tab ? Below is my code public class FoodOrdering { static private JFrame frame; static private JTextField textField; static private GridBagConstraints gbc; static private JLabel[] foodLabel; static private JLabel[] labels; static private JTextField[] qtyField; static private JLabel[] foodImage; static private File[] file; private static final int ELEMENTS = 9; /** * Launch the application. */ public static void main(String[] args) { EventQueue.invokeLater(new Runnable() { public void run() …

Member Avatar
Member Avatar
+0 forum 3

Hey new to JDBC SQL DERBY and Java so I don't know why but my Jtable only shows the columns. Here are my codes for my LeaderboardDAO class. public class LeaderboardDAO extends Dao { private static final Logger LOG = LogManager.getLogger(PlayerDAO.class); public static final String TABLE_NAME = "leaderboard"; private static LeaderboardDAO leaderboardDao; private LeaderboardDAO() { super(TABLE_NAME); } public static LeaderboardDAO getLeaderboardDao() { if (leaderboardDao == null) { leaderboardDao = new LeaderboardDAO(); } return leaderboardDao; } @Override public void create() throws SQLException { LOG.debug("Creating database table " + TABLE_NAME); final String createStatement = "create table leaderboard(wins INTEGER(10), losses INTEGER(10), game_name VARCHAR(64), …

Member Avatar
Member Avatar
+0 forum 4

Flickering occurs when Active Rendering with JPanel, not sure why as I've done this before (couldn't find source code of that project however). Relevant Code: Graphics g = projectDCWindow.getWindowGraphics(); // Gets the Graphics Object from a JFrame g.setColor(Color.BLACK); g.fillRect(0, 0, (int) ProjectDCInfo.getDefaultWindowSize().getWidth(), (int) ProjectDCInfo.getDefaultWindowSize().getHeight()); // Clears the screen projectDCGSM.get().render(g); // Game State Manager which simply draws to the Graphics Object g.dispose(); This is where I draw to the Graphics Object, drawX and drawY are being updated g.setColor(Color.BLUE); g.fillRect(drawX, drawY, 100, 200); The JFrame Code private JFrame projectDCWindow; protected ProjectDCWindow() { projectDCWindow = new JFrame(WINDOW_TITLE); projectDCWindow.setPreferredSize(getDefaultWindowSize()); projectDCWindow.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); projectDCWindow.addWindowListener(new WindowAdapter() { @Override …

Member Avatar
Member Avatar
+0 forum 8

I'm trying to give access to client computer from my server and also tryin to revoke the granted access... the grant is successful but the revoking is not working please help. hms is the satabase that i want to give access to my clients.. my code try { Connection con = getDBConnection(); Statement stmt = con.createStatement(); if (sts == true) { String query = "GRANT INSERT,SELECT,UPDATE,DELETE ON hms.* TO '" + MainFrame.dbUser + "'@'" + ip + "' IDENTIFIED BY '" + MainFrame.dbPassword + "'"; stmt.execute(query); System.out.println(query); JOptionPane.showMessageDialog(null, "Permission granted to '" + ip + "' !"); } else{ String …

Member Avatar
Member Avatar
+0 forum 3

Hello, I try to rename file or directory using JFileChooser() and JButton(). But it gives me a NullPointer exeption. I have FileChooser, Button and TextField where I write new name for my file or directory. Can you say where I go wrong and how to solve this problem. // button action button.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String newFileName = textField.getText(); // exeption here File oldFile = new File(fileChooser.getSelectedFile(), null); File newFileOrDirectoryName = new File(newFileName); if (oldFile.renameTo(newFileOrDirectoryName)) { System.out.println("renamed"); } else { System.out.println("Error"); } } }); This is a full code: package ua.edu.lp; import java.awt.Color; import java.awt.EventQueue; import …

Member Avatar
Member Avatar
+0 forum 2

I have a JTable that a user can input data. I have an image that I would want to put at the top of my page when printed and also another image that I would want to work as footer. How do I print these on the same page including data from for a jtable(my images to works as logo and footer are not part of the table; i would take them from my directories)...I mean make it as shown in the image below. I would appreciate any links and ideas.

Member Avatar
Member Avatar
+0 forum 5

Following is my program i need to add scroll to jframe and I have paint method in it package other; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Container; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.ScrollPane; import java.awt.Stroke; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.geom.Line2D; import javax.swing.*; public class MainDrawCycle extends JPanel implements ActionListener { JButton button; JLabel label; JTextField textField; JScrollPane pane; JPanel panel; JFrame frame; Container c; static int val; int xa,ya,xb,yb,x1,y1; int xc,yc,xd,yd,xe,ye,xf,yf; int lsb=0,msb=7; char val1='A',val2='B'; // public MainDrawCycle(JFrame f) // { // pane=new //JScrollPane(f,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); // add(pane); // } public MainDrawCycle() { setLayout(null); //frame=new JFrame(); // panel=new JPanel(); // pane=new //JScrollPane(panel,JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); …

Member Avatar
Member Avatar
+0 forum 21

hello every body. I need a book at java swing package.i am new in java programming and i want to learn GUI so plz help me. i want to download book of herbert schildt. book name swing a beginner guide Author Herbert Schildt

Member Avatar
Member Avatar
+0 forum 8

Is it possible to call repaint() inside the main()?I have tried the code below.But its not working public mypanel() { initComponents(); repaint(100,150,40,40); } protected void paintComponent(final Graphics g) { final Graphics2D g2 = (Graphics2D)jLabel2.getGraphics(); g2.drawRect(100,150,40,40); } //above code doesnt provide any output private void formMouseClicked(java.awt.event.MouseEvent evt) { repaint(100,150,40,40) } this code draws the rectangle.But I want to draw it when the program execution starts.Please help to solve this(rect angle drawn on an image placed in jLabel).

Member Avatar
Member Avatar
+0 forum 1

Hi, We are facing font issue in our java swing application in linux. Kindly help to solve issue. In our application we are explicity setting font as 'Arial' for labels and others in swing Application. Since Arial is not available in linux so it picks 'Lucida Sans Regular' as default font of java due to font fallback mechanism. But as we upgrade our jdk version from 1.5 to 1.7, we are facing the issue with display in our application. It is now picking up 'Deja vu' as default font. Due to this our application is not displaying correctly in linux. …

Member Avatar
Member Avatar
+0 forum 6

I'm working on a project on my own and wanted to create an JComponent or JFrame that looks like the following screenshot. ![8557bdcb155e0af7b29ae22b32d6f984](/attachments/small/4/8557bdcb155e0af7b29ae22b32d6f984.JPG "align-left") ![8557bdcb155e0af7b29ae22b32d6f984](/attachments/small/4/8557bdcb155e0af7b29ae22b32d6f984.JPG "align-left") ![8557bdcb155e0af7b29ae22b32d6f984](/attachments/small/4/8557bdcb155e0af7b29ae22b32d6f984.JPG "align-left") ![8557bdcb155e0af7b29ae22b32d6f984](/attachments/small/4/8557bdcb155e0af7b29ae22b32d6f984.JPG "align-left") ![8557bdcb155e0af7b29ae22b32d6f984](/attachments/small/4/8557bdcb155e0af7b29ae22b32d6f984.JPG "align-right") Here is its layout. ![e687f5cd32e6536ff8d0e3406b83b9e2](/attachments/small/4/e687f5cd32e6536ff8d0e3406b83b9e2.png "align-left") ![e687f5cd32e6536ff8d0e3406b83b9e2](/attachments/small/4/e687f5cd32e6536ff8d0e3406b83b9e2.png "align-left") I would appreciate it if you showed me by an example, Thanks.

Member Avatar
Member Avatar
+0 forum 7

I'm trying to create a JTextPane that has the following properties: 1. Vowel letters are colored in green 2. Consonants are colored in blue 3. Numbers are colored in red 4. And the maximum number of characters is 26 and all characters are in Upper Case To achieve this I used DocumentListener and DocumentFilter classes and the texts are getting colored but not properly.For example, when I started the program and type 'VOWEL' V is painted in black, O - in blue, W - in blue, E - in blue and L - in Green. But that's not how I …

Member Avatar
Member Avatar
+0 forum 3

Hi! I'd like to create a simple table game by Swing. I have a JFrame and a JPanel variable. I want to add JButtons to this JPanel, but I'd like to create an own class. I made a class that extends JButton (inheritence): public class GameField extends JButton {...} So I could add GameFields to the JPanel. But I'd like to create GameFields by composition: public class GameField{ private JButton button; } But in this clase how I can add GameField to JPanel? Can I solve this problem by compisition?

Member Avatar
Member Avatar
+0 forum 1

Dear All, In Java Swing, for all components there is a setSize method which takes int height and width as arguments. And we will pass parameters like 600,500 & 400,300 etc... My doubt is what is the unit of these height and width . I mean on what unit, the size of the component is rendered. Is it Centimeter,mm,pixels ? Im not sure how these numbers(height and width) contribute to the rendering of the component. Please throw light on it.

Member Avatar
Member Avatar
+0 forum 6

hiii.. I got this strange problem.i m refreshing my jframe after every second.This jframe contains a button called addbutton.This addbutton opens another jframe.and that jframe contains a JComboBox .The problem is after every second the JComboBox is getting refreshed.I dont understand why.Before the user gets time to select any item in the combobox..That combobox again goes to the first element. Can somone pls explain me hw to prevent all this?? Thanks for your time Java Code: public class MarketWatch { static JButton addButton = new JButton("Add"); public static void main(String args[]) { Timer timer = new Timer(); timer.schedule(new TimerTask() { …

Member Avatar
Member Avatar
+0 forum 3

import java.awt.Point; import javax.swing.*; import java.awt.Graphics; import java.awt.event.MouseEvent; import java.awt.event.MouseMotionAdapter; import javax.swing.JPanel; public class painttest extends JPanel { private int pointCount = 0; private Point[] points = new Point[1000]; public painttest(){ addMouseMotionListener(new MouseMotionAdapter() {public void MouseDragged(MouseEvent event){ if(pointCount<points.length) {points[ pointCount ] = event.getPoint(); // find point ++pointCount; // increment number of points in array repaint(); }}});} public void paintComponent( Graphics g ) { super.paintComponent( g ); // clears drawing area // draw all points in array for ( int i = 0; i < pointCount; i++ ) g.fillOval( points[i].x,points[i].y , 4, 4 ); } // end method paintComponent } Hello. …

Member Avatar
Member Avatar
+0 forum 2

import java.awt.Color; import java.awt.event.ItemListener; import java.awt.event.ItemEvent; import javax.swing.*; public class framed implements ItemListener { JToggleButton jtButton; public JPanel createAndShowNewPane() { JPanel GUI= new JPanel(); GUI.setLayout(null); JPanel buttonPane= new JPanel(); buttonPane.setLayout(null); buttonPane.setSize(200,300); buttonPane.setLocation(0,0); GUI.add(buttonPane); jtButton= new JToggleButton("On"); jtButton.setSize(90,50); jtButton.setLocation(100,0); jtButton.addItemListener(this); buttonPane.add(jtButton); return GUI; } public static void window(){ JFrame.setDefaultLookAndFeelDecorated(true); JFrame frame= new JFrame("Hi"); framed frame1= new framed(); frame.setContentPane(frame1.createAndShowNewPane()); frame.setVisible(true); frame.setSize(100,100); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); } public void actionPerformed(ItemEvent e) { if(e.getStateChange() == ItemEvent.SELECTED) { jtButton.setText("Off"); } else { jtButton.setText("On"); }} public static void main(String[] args){ SwingUtilities.invokeLater(new Runnable(){ public void run(){window();} } ); } } Hey, I was just wondering what is up with this. …

Member Avatar
Member Avatar
+0 forum 2

Hi All, I have just finished reading fundamental topics in Java and now i have decided to do a New Project in Java which comprises all basic features of Java. I need help in Understanding/visualizing the architecture / Design model for my Project. Specification is : 1 . Develop a Standalone GUI Application with which user logs in with Credentials and then if its successfull, he gets a Window , the window has few Labels like name,date,descritpion etc and related text fields under the labels for user to enter the information. 2.A user, if he logs in and enters some …

Member Avatar
Member Avatar
+0 forum 12

**I want to enter the value in jtable run time and want to dispaly its sum on same jtable when i pressed calculated button ** how to do please help :) import java.awt.BorderLayout; import java.awt.EventQueue; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.sql.*; import java.util.Vector; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.*; import javax.swing.event.TableModelEvent; import javax.swing.table.DefaultTableModel; public class TestTable { public static void main(String[] args) { TestTable testTable = new TestTable(); } public TestTable() { EventQueue.invokeLater(new Runnable() { @Override public void run() { try { UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException ex) { } JFrame frame = new JFrame("Testing"); …

Member Avatar
Member Avatar
+1 forum 18

Hi! Im new to Java and iv been studying GUI's in it. Just started with swing and tried to make this giu for a calcularot. but it doesnt execute and gives me "java.lang.NoClassDefFoundError" error. im a total noob so i cant figure it out. i'd really appreciate it someone could point out what im doing wrong here :/ .. The following is the code: package Calculator_gui; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Calculator_gui extends JFrame { private JButton btns[]=new JButton[10]; private JButton signBtns[]=new JButton[4]; private JTextField result; public Calculator_gui() { JPanel main_p=new JPanel(new FlowLayout()); result=new JTextField("0",12); result.setEditable(false); main_p.add(result); …

Member Avatar
Member Avatar
+0 forum 3

**Bold Text Here** hey any one can help me sort out my problem.. when i enter the customer id then in tabular format i want its all detail. how to do.. like in textBox i enter customer id as 1 then pressed ok button then in new frame or in its self window i want customer id 1 only detail not others detail.. how to do any one having any idea related to these... thanks in advanced for the help ??

Member Avatar
Member Avatar
+0 forum 1

I am using Netbeans 7.1 and MySQL. I need 1 column in jtable which will contain jradiobutton and user can select any 1 row's jradiobutton Please refer the fig for detail. After selecting RB further processing will be done on jbutton click event. ![64496cca6997d07cf995950d67a3e3f0](/attachments/large/2/64496cca6997d07cf995950d67a3e3f0.JPG "64496cca6997d07cf995950d67a3e3f0") Here is the code - private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) { final Object[] columnNames=new String[] {"Date","Flight Name","Departure Time","BC Seats Available","XC Seats Available","EC Seats Available"}; DefaultTableModel dtm=new DefaultTableModel(columnNames,0); String origin=jComboBox3.getSelectedItem().toString(); String target=jComboBox4.getSelectedItem().toString(); String fclass=jComboBox1.getSelectedItem().toString(); String search = ""; Date dt; //Economy Class Processing try { smt=con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE); rs = smt.executeQuery(sql); int i = 0; SimpleDateFormat sdf= new SimpleDateFormat("dd-MM-yyyy"); …

Member Avatar
Member Avatar
+0 forum 6

I have one tab by default (tab1) New tabs are generated , equal to 'No of rooms'. The dynamically generated tabs have same structure as of the default tab. I don't know the name of textfields of newly generated tabs. How can I find the name of jtexfields generated on tab at run time so I can use .getText()

Member Avatar
Member Avatar
+0 forum 4

Hello, I have created a GUI using the Netbeans GUI Builder and I have a JTextArea that I want to output to, but because I need to use threads I am doing a lot of processing in an external thread. I am having issues outputting data from the thread class to the JTextArea in my main GUI Class. Here is the most important code: // In my MainGui class I have a public JTextArea public javax.swing.JTextArea console; console = new javax.swing.JTextArea(); //I also have a button on this GUI private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) { Thread connect = new Thread(new ConnectThread()); …

Member Avatar
Member Avatar
+0 forum 3

Hi, I wonder if anyone can possibly help. I am trying to teach myself how to integrate a Java video into a Java GUI / Swing Application. I am pretty competent with building Java graphical user interfaces and the background Java application code, however I am puzzled with how difficult it seems to be to integrate local video. I am attempting to build a graphical single screen application which has an array of buttons etc on, but also 5 different videos (which are controlled from the same control buttons (play, pause, rewind etc)). The video format can be AVI, MPEG, …

Member Avatar
Member Avatar
+0 forum 1

I need some help figuring out where I have gone wrong on my program. It is a classic classroom program, where the program creates a random number and gives high, low response untill the user enters the correct number. I have the GUI working and I know the action to test the number is correct. When I run it the GUI comes up properly, I can enter a number, but once I hit the button I get a really long error message. The error message starts off with "Exception in thread "AWT-EventQueue-0" java.NullPointerException..... I have pasted my code. Could someone …

Member Avatar
Member Avatar
+0 forum 5

- Please how is possible (probably dirty hack) to create [How to Create Translucent and Shaped Windows](http://docs.oracle.com/javase/tutorial/uiswing/misc/trans_shaped_windows.html) - undecorated container (returns *java.awt.IllegalComponentStateException: The frame is displayable.*) - change Look and Feel for (returns *AWT-EventQueue-0" java.awt.IllegalComponentStateException: The frame is decorated*) - by using code from linked official tutorial . import java.awt.*; import javax.swing.*; public class TranslucentWindow extends JFrame { private static final long serialVersionUID = 1L; public TranslucentWindow() { super("Test translucent window"); setLayout(new FlowLayout()); add(new JButton("test")); add(new JCheckBox("test")); add(new JRadioButton("test")); add(new JProgressBar(0, 100)); JPanel panel = new JPanel() { @Override public Dimension getPreferredSize() { return new Dimension(400, 300); } private static …

Member Avatar
Member Avatar
+1 forum 3

I am making an examination system desktop application in Java Swing. I have a frame named 'show_class_question' frame. This frame is used to display questions and four options from database. Whenever user clicks 'Next' button I am calling this same frame (show_class_question) again and agian from itself (self - refrencing) upto total number of questions (say 20). **show_class_question --**(user clicks next button on it)**--> show_class_question** Now I would like to add a countdown timer, whose value will be retrieved from database. I have stored minutes in database in an int column. And whenever user clicks next button the remaining time …

Member Avatar
Member Avatar
+0 forum 7

Hello, I was hoping someone can help me, im looking for a way to extend a basic shape class in particular the roundedrectangle2d class and be able to draw it in the same way we could handle an object with a simple call to g.draw(object instance); However im having problems with it not being drawn to the canvas, i only see a gray rectangle for the code below : import java.awt.BasicStroke; import java.awt.Canvas; import java.awt.Color; import java.awt.Dimension; import java.awt.Graphics; import java.awt.Graphics2D; import javax.swing.JComponent; public class objectView extends JComponent { private static final long serialVersionUID = 1L; public objectView() { } …

Member Avatar
Member Avatar
+0 forum 2

The End.