Disable a Tab in a JTabbedPane Container with Java

George John
Updated on 30-Jul-2019 22:30:26

3K+ Views

To disable a tab in a JTabbedPane container, use the setEnabledAt() method and set it to false with the index of the tab you want to disable.Let’s first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, let us disable a tab at index 2 −tabbedPane.setEnabledAt(2, false);The following is an example to disable a tab in a JTabbedPane Container −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Devices");       JTabbedPane tabbedPane = new JTabbedPane();       JTextArea text = new JTextArea(100, 100); ... Read More

Get Rows with GROUP BY in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:26

243 Views

Let us first create a table −mysql> create table DemoTable    (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Subject varchar(20),    Price int    ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MySQL', 456); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 56); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(Subject, Price) values('MongoDB', 60); Query OK, 1 row affected (0.13 sec) mysql> ... Read More

Store and Retrieve Boolean Values in Varchar2 Column Using JDBC

Anvi Jain
Updated on 30-Jul-2019 22:30:26

602 Views

Yes, in Oracle you can store and retrieve a boolean value into a table for a column with VARCHAR2 datatype.If you do so, the true and false values are stored as 1 and 0 and the retrieved as same (respectively).ExampleLet us create a table with name sampleTable in the Oracle database Using CREATE statement as −CREATE TABLE sampleTable(    ID INT,    ProductName VARCHAR (20) NOT NULL,    CustomerName VARCHAR (20) NOT NULL,    IsBillDue VARCHAR (20) NOT NULL,    DeliveryDate date,    Price INT,    Location varchar(20) );The column IsBillDue specified whether bill paid.Following JDBC program establishes the connection ... Read More

Extract Substring from a String Starting at a Particular Position in MySQL

Kumar Varma
Updated on 30-Jul-2019 22:30:26

254 Views

For this, you can use the mid() function. Following is the syntax −select mid(yourColumnName, yourPositionToStart, yourEndValue) as anyAliasName from yourTableName;Let us first create a table −mysql> create table DemoTable    -> (    -> Title text    -> ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command −mysql> insert into DemoTable values('My best framework is Spring and Hibernate'); Query OK, 1 row affected (0.21 sec)Display all records from the table using select statement −mysql> select *from DemoTable;Output+-------------------------------------------+ | Title ... Read More

Absolute Difference Between the Sum of Non-Prime and Prime Numbers of an Array

Arnab Chakraborty
Updated on 30-Jul-2019 22:30:26

232 Views

Here we will see how we can find the absolute difference between the sum of all prime numbers and all non-prime numbers of an array. To solve this problem, we have to check whether a number is prime or not. One possible way for primality testing is by checking a number is not divisible by any number between 2 to square root of that number. So this process will take 𝑂(√𝑛) amount of time. Then get the sum and try to find the absolute difference.AlgorithmdiffPrimeNonPrimeSum(arr)begin    sum_p := sum of all prime numbers in arr    sum_np := sum of ... Read More

When to Use Yield Instead of Return in Python

Chandu yadav
Updated on 30-Jul-2019 22:30:26

1K+ Views

In short, whenever control reach the return statement in your program, the execution of the program is terminated and the remaining statements will not executed.However, in case of yield, whenever control reach the yield statement in your program, the execution of your program is paused and later we can continue other statements in function.Let’s understand both the statements in detail.YieldUsing yield statement in a function makes the function a generator function which can be used in a loop. When the function is running and the yield statement exeucutes, the value after the yield is passed back to the loop that ... Read More

Remove Record from Existing Table in Oracle Database Using JDBC API

Vikyath Ram
Updated on 30-Jul-2019 22:30:26

610 Views

You can remove a particular record from a table in a database using the DELETE query.SyntaxDELETE FROM table_name WHERE [condition];To delete a record from a table using JDBC API you need to −Register the Driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect to the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the executeUpdate() method of the ... Read More

Check If a Field in MongoDB is OR

Nishtha Thakur
Updated on 30-Jul-2019 22:30:26

176 Views

To check if a field in MongoDB is [] or {}, you can use the following syntax −db.yourCollectionName.find({    "yourOuterFieldName": { "$gt": {} },    "yourOuterFieldName.0": { "$exists": false } });Let us first create a collection with documents -> db.checkFieldDemo.insert([ ...   { _id: 1010, StudentDetails: {} }, ...   { _id: 1011, StudentDetails: [ { StudentId: 1 } ] }, ...   { _id: 1012, StudentDetails: [ {} ] }, ...   { _id: 1013 }, ...   { _id: 1014, StudentDetails: null}, ...   { _id: 1015, StudentDetails: { StudentId: 1 } } ... ]); BulkWriteResult({    "writeErrors" ... Read More

Change Default Font of JTabbedPane Tabs in Java

George John
Updated on 30-Jul-2019 22:30:26

416 Views

To display the default font of the tabs, you need to use the Font class. Let’s say we created a JTabbedPane in Java −JTabbedPane tabbedPane = new JTabbedPane();Now, set the Font with font face, style and font size −Font font = new Font("Arial", Font.CENTER_BASELINE, 20); tabbedPane.setFont(font);The following is an example to change the default font of the JTabbedPane tabs −package my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) {       JFrame frame = new JFrame("Technologies");       JTabbedPane tabbedPane = new JTabbedPane();       JPanel panel1, panel2, panel3, panel4, ... Read More

Set Color of a Single Tab's Text in JTabbedPane in Java

Arjun Thakur
Updated on 30-Jul-2019 22:30:26

493 Views

To set the the color of a single tab’s text, use the setForegroundAt() method. This gives an option to mention the index and the color. The index here is the index of the specific tab you want to color the text.Let us first create a JTabbedPane −JTabbedPane tabbedPane = new JTabbedPane();Now, set the background color for one of the tabs with index 2 −tabbedPane.setForegroundAt(2, Color.RED);The following is an example wherein we will update the foreground color of a single tab in the JTabbedPane −Examplepackage my; import javax.swing.*; import java.awt.*; public class SwingDemo {    public static void main(String args[]) { ... Read More

Advertisements